multithreading

Asynchronous operations within a loop - how to keep control of execution?

一曲冷凌霜 提交于 2021-01-29 19:05:26
问题 Follow-on question to this one. I am trying to generate and save a series of images. Rendering is done by Helix Toolkit, which I am told utilises the WPF composite render thread. This is causing problems because it executes asynchronously. My original problem was that I couldn't save a given image because it hadn't yet been rendered at that time I was trying to save it. The above answer provides a workaround to this by putting the 'save' operation inside an Action which is called with low

multi threaded processes in python using queue to write to file checking if work had been done

社会主义新天地 提交于 2021-01-29 18:38:51
问题 from multiprocessing.dummy import Pool as ThreadPool import multiprocessing as mp def func(a): pthData = "C:/temp/temp.txt" with open(pthData, 'r') as file: done = file.read().splitlines() if a in done: return 'done' q.put(a) return a def listener(q): pthData = "C:/temp/temp.txt" m = q.get() with open(pthData, 'a') as the_file: the_file.write( m + '\n') #he_file.write(str(m) + '\n') a = ['a', 'b', 'c', 'd', 'a', 'b'] # Make the Pool of workers pool = ThreadPool(4) #must use Manager queue here

Memory leaks in pthread even if the state is detached

穿精又带淫゛_ 提交于 2021-01-29 18:37:55
问题 I am learning pthreads programming. I understood that there are two states of thread: 1. Joinable 2. Detachable In case of Joinable, we need to call pthread_join to free the resources(stack), whereas in case of detached there is no need to call pthread_join and the resources will be freed on thread exit. I wrote a sample program to observe the behavior #include <stdio.h> #include <pthread.h> #include <stdlib.h> void *threadFn(void *arg) { pthread_detach(pthread_self()); sleep(1); printf(

How to paint in Java Swing in every concurrent thread?

心不动则不痛 提交于 2021-01-29 18:08:21
问题 The goal of my program is to draw squares from randomly generated points. I want to display a set of squares as soon as they are generated by each thread. However, only one set of squares displays, once all the threads are done running. I have used swinginvoke, and am curious as if there is a problem with repaint() since all the threads reach repaint but don't paint until the final thread is done, and end up overlapping each other. I also don't want the "storedata" variable to be shared

Java- Allow one thread to update a value, others to wait and skip critical section

不羁岁月 提交于 2021-01-29 18:01:21
问题 Hi I have a situation in which I have to allow only one thread to say update a variable. There is a trigger, which might invoke multiple threads to update this variable, however the update should happen only once by the first thread whichever arrives at the critical section. Ideally the flow should be like follows: Thread-1; Thread-2 and Thread-3 are invoked to update a variable in critical section guarded by a lock or a mutex Critical section using this guard allows only one thread to enter,

Make multiple API calls and return combined response in minimum time

ε祈祈猫儿з 提交于 2021-01-29 17:07:23
问题 I have 10 health check URLs which are simply get service I am hitting them in a loop like below for(int i=0;i<10;i++){ Response response = given().when().relaxedHttpsValidation().get(url[i]); list.add(response); } return list; Now the problem is it hits API in series and waiting for a response for all, I just want to hit all API in parallel but combine the result, I tried using threads but unable to get an idea on how to combine the response in case of multi-threading 回答1: If I am reading

C# Monitor/Semaphore Concurrency Produce-Consumer for Buffer

自作多情 提交于 2021-01-29 17:05:00
问题 I am working on solving a problem with the typical producer-consumer problem. I have multiple producers, and one consumer. There are n producer threads that each call SetOne(OrderObject order) and the consumer calls GetOne() . The Buffer class is used as the buffer which contains < n cells and are each cell are consumed when available by the Buffer class. For some reason, the setup below is working sometimes, but is not always consuming all of the cells. I have included all the classes that

Pass *this as argument to method invoked by thread

南笙酒味 提交于 2021-01-29 15:58:18
问题 I have a member function which I cannot unit test easily (it listens to sockets etc): void MyClass::func() { listen(); send(); } So I want to template it and then I can pass a mock object in my test: template<class OBJECT> void func(OBJECT& obj) { obj.listen(); obj.send(); } and then I'd do: func(*this); The above compiles when I do a normal function call. However, when I spawn a thread and call it: std::thread t1(&MyClass::func, this, *this); I get compiler errors (see below) referring to

Why cross-thread exception only thrown when you change visible properties of a control?

本秂侑毒 提交于 2021-01-29 15:11:33
问题 I have noticed that if I change a visible property of a control, such as label1.Text, from another thread that did not create the control, Visual Studio will throw an invalid cross-thread operation exception. But if I change a non-visible property of the control, say label1.Name, then no exception is thrown. Why is that? 来源: https://stackoverflow.com/questions/65839267/why-cross-thread-exception-only-thrown-when-you-change-visible-properties-of-a-c

Multiprocessing.Queue deadlocking during Process spawning

风流意气都作罢 提交于 2021-01-29 14:33:44
问题 Let me start with thank you for taking the time for reading this. First off I would like to start to share my code, see blow. It is around 200 lines of code but most of the lines are property definitions. Some context: I am just trying to get a beter understanding of multiprocessing so I went and made a small project to try and run multiple processes which all share a single input and output queue. It works, but sometimes it deadlocks right after calling the scheduler.start() method. I am