multithreading

Processing tasks in parallel and sequentially Java

↘锁芯ラ 提交于 2021-02-10 05:35:21
问题 In my program, the user can trigger different tasks via an interface, which take some time to process. Therefore they are executed by threads. So far I have implemented it so that I have an executer with one thread that executes all tasks one after the other. But now I would like to parallelize everything a little bit. i.e. I would like to run tasks in parallel, except if they have the same path, then I want to run them sequentially. For example, I have 10 threads in my pool and when a task

asio::io_service is ending immediately with work

亡梦爱人 提交于 2021-02-10 05:12:38
问题 I'm trying to learn io_service and work with shared pointers. I want the code to work infinitely until I call stop method or sth like this. Unfortunately after seeing workHandler's output on the screen the program shutdowns. Can anybody explain why this happen? #include <boost/asio.hpp> #include <iostream> #include <atomic> #include <memory> #include <thread> #include <vector> class Service : public std::enable_shared_from_this<Service> { std::shared_ptr<boost::asio::io_service> _service; std

Synchronizing embedded Python in multi-threaded program

别等时光非礼了梦想. 提交于 2021-02-10 04:41:27
问题 Here is the example of using Python interpreter in multi-threaded program: #include <python.h> #include <boost/thread.hpp> void f(const char* code) { static volatile auto counter = 0; for(; counter < 20; ++counter) { auto state = PyGILState_Ensure(); PyRun_SimpleString(code); PyGILState_Release(state); boost::this_thread::yield(); } } int main() { PyEval_InitThreads(); Py_Initialize(); PyRun_SimpleString("x = 0\n"); auto mainstate = PyEval_SaveThread(); auto thread1 = boost::thread(f, "print(

Synchronizing embedded Python in multi-threaded program

别来无恙 提交于 2021-02-10 04:40:19
问题 Here is the example of using Python interpreter in multi-threaded program: #include <python.h> #include <boost/thread.hpp> void f(const char* code) { static volatile auto counter = 0; for(; counter < 20; ++counter) { auto state = PyGILState_Ensure(); PyRun_SimpleString(code); PyGILState_Release(state); boost::this_thread::yield(); } } int main() { PyEval_InitThreads(); Py_Initialize(); PyRun_SimpleString("x = 0\n"); auto mainstate = PyEval_SaveThread(); auto thread1 = boost::thread(f, "print(

Synchronizing embedded Python in multi-threaded program

末鹿安然 提交于 2021-02-10 04:40:09
问题 Here is the example of using Python interpreter in multi-threaded program: #include <python.h> #include <boost/thread.hpp> void f(const char* code) { static volatile auto counter = 0; for(; counter < 20; ++counter) { auto state = PyGILState_Ensure(); PyRun_SimpleString(code); PyGILState_Release(state); boost::this_thread::yield(); } } int main() { PyEval_InitThreads(); Py_Initialize(); PyRun_SimpleString("x = 0\n"); auto mainstate = PyEval_SaveThread(); auto thread1 = boost::thread(f, "print(

Spreading OpenMP threads among NUMA nodes

陌路散爱 提交于 2021-02-10 04:16:51
问题 I have a matrix spread among four NUMA-node local memories. Now I want to open 4 threads, each one on a CPU corresponding to a different NUMA-node, so that each thread can access its part of the matrix as fast as possible. OpenMP has the "proc_bind(spread)" option, but it puts the threads on the same NUMA-node, but on far apart CPUs. How can I force the threads to bind to different NUMA nodes? Or, if that is not possible: When I use all cores on all nodes (256 threads total), I know how to

compareAndSet on processors that does not support CAS operation

早过忘川 提交于 2021-02-10 03:31:00
问题 Today I was asked the next question on an interview: "What is going on with compareAndSet method from AtomicLong in case you call it on a machine with a processor that does not support CAS operation". Could you please help me with this question and provide some links to a comprehensive description if possible? 回答1: From Java Concurrency in Practice 15.2.3 CAS support in the JVM : On platforms supporting CAS, the runtime inlines them into the appropriate machine instruction(s); in the worst

compareAndSet on processors that does not support CAS operation

别说谁变了你拦得住时间么 提交于 2021-02-10 03:28:57
问题 Today I was asked the next question on an interview: "What is going on with compareAndSet method from AtomicLong in case you call it on a machine with a processor that does not support CAS operation". Could you please help me with this question and provide some links to a comprehensive description if possible? 回答1: From Java Concurrency in Practice 15.2.3 CAS support in the JVM : On platforms supporting CAS, the runtime inlines them into the appropriate machine instruction(s); in the worst

Execute multiple AJAX request parallel without waiting for others to respond

梦想与她 提交于 2021-02-10 03:01:58
问题 I have the problem that i need to execute multiple AJAX requests on one Page. The request start all at the same time but they seem to wait for their predecessor to return. Lets say that page1 needs about 3 seconds to load. And page2 needs 2 seconds to load. What i get is that both start at the same time and the page1 request returns after 3 secons. But the problem is that the page2 request returns after 5 seconds. Why is that so ? I thought that every AJAX request will run in it's own thread.

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

烂漫一生 提交于 2021-02-09 14:35:10
问题 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