multithreading

Why is this multithreaded program getting stuck at infinite loop?

喜夏-厌秋 提交于 2021-02-10 14:53:17
问题 The below program is a simple threaded program . For some reason which i am not able to figure , its getting stuck at infinite loop of both produce() and consume() methods simultaneously in both the threads. It produces the output for a few times and then there is no output at the console. So I presume its getting stuck at the loop. My question is , since the loop depends on the value of the flag valueSet of the same object of Item class , valueSet can't be both true and false at the same

Terminate threads when SIGINT is called - C

谁说胖子不能爱 提交于 2021-02-10 14:51:05
问题 I'm building a generic program written in C-UNIX (using Linux so I don't care about BSD or WIN functions), that creates two threads to handle the communication with a server. void init_threads(int socket_desc) { pthread_t chat_threads[2]; ret = pthread_create(&chat_threads[0], NULL, receiveMessage, (void*)(long)socket_desc); PTHREAD_ERROR_HELPER(ret, "Errore creazione thread ricezione messaggi"); ret = pthread_create(&chat_threads[1], NULL, sendMessage, (void*)(long)socket_desc); PTHREAD

Killing all processes and threads in python3.X

柔情痞子 提交于 2021-02-10 14:50:20
问题 I'm writing a UI wrapper for reading some info using esptool.py I have two active threads: UI and procesing - SerialReader. UI class has reference to the SerialReader and should stop SerialReader when it gets the exit command. The problem is that I call esptool command which gets stuck in trying to read data over serial connection. class SerialReaderProcess(threading.Thread): def __init__(self, window): super().__init__() self.window = window self.logger = window.logger self.window.set_thread

How do I know when all threads in a ExecutorService are finished?

人盡茶涼 提交于 2021-02-10 14:24:48
问题 I know that shutdown() and awaitTermination() exist. The problem is that the runnables in the pool need to be able to add an unknown number (can't use a countdownlatch) of other runnables to it and if I call shutdown() those tasks will be rejected. How can I know when they're done? 回答1: Instead of submitting Runnable tasks to an Executor , you should rather use ForkJoinTask/ForkJoinPool instead. A ForkJoinTask runs inside a ForkJoinPool and can spawn an arbitrary number of (sub)tasks and wait

C# threading: calling a function on a different thread in its context and returning results

我的未来我决定 提交于 2021-02-10 14:21:03
问题 This might be a very naive question: I'm trying to create a client application that uses ZeroMQ for communicating to multiple servers. The client would like to send a large number of requests to these servers and get responses to them (so req-rep pattern). The issue I'm facing is that ZeroMQ sockets should only be used in the threads they are created on. One way is to invoke each of the requests in a new task: inside the task, create a connection, send request and get response. However, the

Embed Python/C API in a multi-threading C++ program

有些话、适合烂在心里 提交于 2021-02-10 14:20:49
问题 I am trying to embed Python in a C++ multi-threading program using the Python/C API (version 3.7.3) on a quad-core ARM 64 bit architecture. A dedicated thread-safe class "PyHandler" takes care of all the Python API calls: class PyHandler { public: PyHandler(); ~PyHandler(); bool run_fun(); // ... private: PyGILState_STATE _gstate; std::mutex _mutex; } In the constructor I initialize the Python interpreter: PyHandler::PyHandler() { Py_Initialize(); //PyEval_SaveThread(); // UNCOMMENT TO MAKE

Embed Python/C API in a multi-threading C++ program

帅比萌擦擦* 提交于 2021-02-10 14:20:43
问题 I am trying to embed Python in a C++ multi-threading program using the Python/C API (version 3.7.3) on a quad-core ARM 64 bit architecture. A dedicated thread-safe class "PyHandler" takes care of all the Python API calls: class PyHandler { public: PyHandler(); ~PyHandler(); bool run_fun(); // ... private: PyGILState_STATE _gstate; std::mutex _mutex; } In the constructor I initialize the Python interpreter: PyHandler::PyHandler() { Py_Initialize(); //PyEval_SaveThread(); // UNCOMMENT TO MAKE

Thread Safety in Scala reflection with type matching

无人久伴 提交于 2021-02-10 14:16:32
问题 Working in scala 2.11.12, JDK 1.8.0_131, I have been able to replicate a thread safety bug observed in Apache Spark with the following code, in which I repeatedly check with multiple threads whether Option[Int] can be matched via <:< to Option[_] : package stuff import java.util.concurrent.{Executors, Future} import scala.collection.mutable.ListBuffer object Main { val universe: scala.reflect.runtime.universe.type = scala.reflect.runtime.universe import universe._ def mirror: universe.Mirror

Thread Safety in Scala reflection with type matching

▼魔方 西西 提交于 2021-02-10 14:15:47
问题 Working in scala 2.11.12, JDK 1.8.0_131, I have been able to replicate a thread safety bug observed in Apache Spark with the following code, in which I repeatedly check with multiple threads whether Option[Int] can be matched via <:< to Option[_] : package stuff import java.util.concurrent.{Executors, Future} import scala.collection.mutable.ListBuffer object Main { val universe: scala.reflect.runtime.universe.type = scala.reflect.runtime.universe import universe._ def mirror: universe.Mirror

python threading - best way to pass arguments to threads

不问归期 提交于 2021-02-10 13:43:32
问题 I was wondering what would be the best way, performance wise, to pass shared arguments to threads (e.g. an input Queue). I used to pass them as arguments to the __init__ function, because that's what I saw in most of the examples out there in the internet. But I was wondering whether it would be faster to set them as class variables, is there a reason not to do that? Here is what I mean: class Worker(threading.Thread): def __init__(self, in_q): self.in_q = in_q or: class Worker(threading