multithreading

NSOperation with dependency on another operation on a different queue does not start

心不动则不痛 提交于 2021-02-09 14:34:33
问题 I have dependency graph of operations and I use multiple queues to organize various streams of operations. E.g. peopleQueue, sitesQueue, sessionQueue sessionQueue: loginOp, fetchUpdatedAccountOp peopleQueue: mostFrequentlyManagedClientsOp, remainingClientsOp sitesQueue: mostFrequentlyAccessedSitesOp, remainingSitesOp dependencies: *all* -> loginOp remainingClientsOp -> mostFrequentlyManagedClientsOp remainingSitesOp -> mostFrequentlyAccessedSitesOp The current setup works: after login

Thread sanitizer reports data race when using std::packaged_task/std::exception_ptr

心不动则不痛 提交于 2021-02-09 11:00:45
问题 I am experiencing some issues with thread sanitizer (TSan) complaining about a data race in some production code where std::packaged_task are handed over to a dispatcher thread by wrapping them in a std::function. For this question I have simplified what it does in production, while triggering TSan. The implementation is similar to the answer given by Anthony Williams in this question (at least that is my understanding): Non-obvious lifetime issue with std::promise and std::future. Note that

Thread sanitizer reports data race when using std::packaged_task/std::exception_ptr

☆樱花仙子☆ 提交于 2021-02-09 11:00:27
问题 I am experiencing some issues with thread sanitizer (TSan) complaining about a data race in some production code where std::packaged_task are handed over to a dispatcher thread by wrapping them in a std::function. For this question I have simplified what it does in production, while triggering TSan. The implementation is similar to the answer given by Anthony Williams in this question (at least that is my understanding): Non-obvious lifetime issue with std::promise and std::future. Note that

concurrent.futures.ThreadPoolExecutor doesn't print errors

狂风中的少年 提交于 2021-02-09 09:37:25
问题 I am trying to use concurrent.futures.ThreadPoolExecutor module to run a class method in parallel, the simplified version of my code is pretty much the following: class TestClass: def __init__(self, secondsToSleepFor): self.secondsToSleepFor = secondsToSleepFor def testMethodToExecInParallel(self): print("ThreadName: " + threading.currentThread().getName()) print(threading.currentThread().getName() + " is sleeping for " + str(self.secondsToSleepFor) + " seconds") time.sleep(self

Pythoncom PumpMessages from different thread

*爱你&永不变心* 提交于 2021-02-09 08:25:09
问题 I want to do something similar to what is asked here, but using threading like here. Using also the answer from here, I got my code working, only that an ItemAdd event is not recognised (actually, I think it is, but in the other thread, which is why there is no output). """Handler class that watches for incoming mails""" import ctypes # for the WM_QUIT to stop PumpMessage() import logging import win32com.client import sys import threading import time import pythoncom # outlook config CENTRAL

Implement a thread-safe ArrayList in Java by locking

此生再无相见时 提交于 2021-02-09 07:32:19
问题 I want to write a simple thread-safe arraylist which supports: add(), remove(int i), insert(int i), update(int i), and get(int i) One simple implementation is to add lock to the internal data structure(an object array for example), but it is not good enough because only one thread could access the list at a time. Therefore my initial plan is to add lock to each data slot so that different threads could have access to elements in different indexes at the same time. The data structure will look

Implement a thread-safe ArrayList in Java by locking

三世轮回 提交于 2021-02-09 07:31:21
问题 I want to write a simple thread-safe arraylist which supports: add(), remove(int i), insert(int i), update(int i), and get(int i) One simple implementation is to add lock to the internal data structure(an object array for example), but it is not good enough because only one thread could access the list at a time. Therefore my initial plan is to add lock to each data slot so that different threads could have access to elements in different indexes at the same time. The data structure will look

Implement a thread-safe ArrayList in Java by locking

≯℡__Kan透↙ 提交于 2021-02-09 07:27:10
问题 I want to write a simple thread-safe arraylist which supports: add(), remove(int i), insert(int i), update(int i), and get(int i) One simple implementation is to add lock to the internal data structure(an object array for example), but it is not good enough because only one thread could access the list at a time. Therefore my initial plan is to add lock to each data slot so that different threads could have access to elements in different indexes at the same time. The data structure will look

python executor spawn tasks from done callback (recursively submit tasks)

你。 提交于 2021-02-09 01:57:52
问题 I'm trying to submit further tasks from result of a task that was done: with concurrent.futures.ThreadPoolExecutor() as executor: future = executor.submit(my_task) def callback(future): for another_task in future.result(): future = executor.submit(another_task) future.add_done_callback(callback) future.add_done_callback(callback) but I'm getting: RuntimeError: cannot schedule new futures after shutdown What's the best way to make the executor hold for the callback? A semaphore? Ideally the

python executor spawn tasks from done callback (recursively submit tasks)

血红的双手。 提交于 2021-02-09 01:57:14
问题 I'm trying to submit further tasks from result of a task that was done: with concurrent.futures.ThreadPoolExecutor() as executor: future = executor.submit(my_task) def callback(future): for another_task in future.result(): future = executor.submit(another_task) future.add_done_callback(callback) future.add_done_callback(callback) but I'm getting: RuntimeError: cannot schedule new futures after shutdown What's the best way to make the executor hold for the callback? A semaphore? Ideally the