multithreading

Simultaneous input and output in a console

﹥>﹥吖頭↗ 提交于 2021-02-10 12:23:10
问题 A thread where it prints values infinitely to console and a main thread which is taking user input from the console, but the input values are being mixed with the output of that thread. C++ : cin while cout Did give me a hint on how to move further but I was not able to come up with a solution of my own(as I am new to c++). using namespace std; mutex mtx; void foo() { while (1) { usleep(1000000); cout << "Cake\n"; } } int main() { mtx.lock(); thread t1(foo); string x; while (true) { cin >> x;

Simultaneous input and output in a console

岁酱吖の 提交于 2021-02-10 12:23:09
问题 A thread where it prints values infinitely to console and a main thread which is taking user input from the console, but the input values are being mixed with the output of that thread. C++ : cin while cout Did give me a hint on how to move further but I was not able to come up with a solution of my own(as I am new to c++). using namespace std; mutex mtx; void foo() { while (1) { usleep(1000000); cout << "Cake\n"; } } int main() { mtx.lock(); thread t1(foo); string x; while (true) { cin >> x;

How to dynamically lock strings but remove the lock objects from memory

江枫思渺然 提交于 2021-02-10 09:43:13
问题 I have the following situation: I have a lot of threads in my project, and each thread process one "key" by time. Two threads cannot process the same "key" at the same time, but my project process A LOOOOOT OF KEYS, so I can't store the "keys" on memory, I need to store on memory that a thread is processing a "key" and if another thread tries to process the same "key" this thread will be waiting in a lock clause. Now I have the following structure: public class Lock { private static object

Stop and restart a already running thread

百般思念 提交于 2021-02-10 08:44:28
问题 The Thread should end if I press a button, which sets the isButtonPressed to true. My problem is, that if a want to start the thread with thread.start(runnable) by clicking the button, I get this: IllegalThreadStateException: Thread already started (I thought the thread was terminated after the break because the the loop is over, but it seems that I am wrong). Thread thread = new Thread(runnable); thread.start(runnable); The runnable Runnable: Runnable runnable = new Runnable() { @Override

How to organize a HIERARCHY of non-UI threads and get status and progress back for UI consumption

廉价感情. 提交于 2021-02-10 07:26:20
问题 Figure 1 - Working Demo I'm running a winforms application and I have implemented a status / progress TreeView. It can display the status (by icon) and progress of a (possibly hierarchical) set of tasks to accomplish. My question is not about how to implement the TreeView control itself. I've got that part covered. The TreeView is merely the way the background work is going to status / progress itself to the user. I have a set of methods that I want to run on not the main UI thread. They need

Xamarin Using async./wait VS await Task.Run (in Xamarin)

拟墨画扇 提交于 2021-02-10 07:04:13
问题 I have been researching about async/await vs await Task.Run but have not found a definite conclusion. Does "async/await" always run on a separate thread from the UI? And if yes why use "await Task.Run"? From my research, the recommendation is to use "await Task.Run" for CPU intensive tasks and "await/async" for data transfer scenarios (I/O) but others have recommended using await Task.Run (if needing the return) or just Task.Run (fire and forget) for ANY longer running activities in Xamarin.

How to correctly lock Qthreads in pyqt5 using Python3

…衆ロ難τιáo~ 提交于 2021-02-10 06:29:09
问题 I am relatively new to python, but was able to get a reasonably useful program to run to crunch a lot of data. I am able to run it over multiple sets of data sequentially using another python script to call the program serially, but I wanted to create a GUI and use multithreading to allow others to use it without knowing all the ins and outs of programming. I created the GUI successfully, and can feed data bidirectionally using signals and slots. What I am having trouble with is creating

PCRE pcre_exec thread safe?

自作多情 提交于 2021-02-10 06:14:03
问题 I have a C program that uses a PCRE regex to determine if a process in a cgroup should be added to one variable or another. I spawn a thread to read the cpuacct.stat file in each running cgroup, where the number of threads never exceeded the number of cores. These samples and results are then combined into one of two variables. The relevant snippet of code is: pcreExecRet = pcre_exec(reCompiled, pcreExtra, queue, strlen(queue), // length of string 0, // Start looking at this point 0, //

PCRE pcre_exec thread safe?

孤人 提交于 2021-02-10 06:13:05
问题 I have a C program that uses a PCRE regex to determine if a process in a cgroup should be added to one variable or another. I spawn a thread to read the cpuacct.stat file in each running cgroup, where the number of threads never exceeded the number of cores. These samples and results are then combined into one of two variables. The relevant snippet of code is: pcreExecRet = pcre_exec(reCompiled, pcreExtra, queue, strlen(queue), // length of string 0, // Start looking at this point 0, //

C: blocking read should return, if filedescriptor is deleted

蹲街弑〆低调 提交于 2021-02-10 05:51:48
问题 I am reading in a blocked way from a device/filedescriptor. It might happen, that in a different thread the device is closed and filedescriptor is deleted. Unfortunatly the read doesn't return or take notice and keeps blocking. As a workaround I could do a while loop with select as a timeout. If a timeout happens, I can check the filedescriptor and in case it is gone not calling read but return. I am wondering, if there is a better way in Linux-C ? 回答1: The code you are describing has an