multithreading

Resetting sleeping time of a thread

自作多情 提交于 2021-01-27 07:42:42
问题 Suppose to have a thread like this void mythread() { int res; while(1) { { boost::lock_guard<boost::mutex> lock(mylock); res = do_my_stuff(); } boost::this_thread::sleep(boost::posix_time::seconds(5)); } } and that the thread is currently sleeping. If something happens outside of the thread, I'd like to be able to increase the sleep time. What is the best way to do it? 回答1: Using a condition_variable to signal changes to the deadline This has the benefit of supporting scenarios where the

Could not set thread-stack size in mysql

牧云@^-^@ 提交于 2021-01-27 07:38:18
问题 I'm trying to increase thread-stack variable. I can do it successfully using command-line option as such: /usr/sbin/mysqld --thread-stack=256k I can also do it using configuration files /etc/init/mysql.conf or /etc/init.d/mysql : thread_stack=262144 thread_stack=256k thread-stack=256k thread-stack=262144 However, setting through /etc/mysql/my.cnf doesn't work. show variables like'%thread_stack%'; still shows the default 196608 . Why does setting through /etc/mysql/my.cnf not work? How do I

DelayQueue implementation in Java

南笙酒味 提交于 2021-01-27 07:07:59
问题 I'm a beginner in understanding threads and concurrency package. Understood that to use java.util.concurrent.DelayedQueue we have to implement the java.util.concurrent.Delayed interface and it has a abstract method getDelay() long getDelay(TimeUnit unit) Returns the remaining delay associated with this object, in the given time unit. @Override public long getDelay(TimeUnit unit) { long diff = startTime - System.currentTimeMillis(); // long variable return unit.convert(diff, TimeUnit

Unable to load dynamic library 'C:\php\ext\php_pthreads.dll'

*爱你&永不变心* 提交于 2021-01-27 07:01:27
问题 I'm trying to have threads in my php code, but I can't get my head around pthreads library and every time I run my program I encounter this error: Warning: PHP Startup: Unable to load dynamic library 'C:\php\ext\php_pthreads.dll' - The specified module could not be found.in Unknown on line 0 I followed every step needed: I've added the file pthreadVC2.dll in my "C:\php" folder I've added the file php_pthreads.dll in my "C:\php\ext"folder I've modified the file php.ini, enabling the extension:

Unable to load dynamic library 'C:\php\ext\php_pthreads.dll'

痞子三分冷 提交于 2021-01-27 07:00:39
问题 I'm trying to have threads in my php code, but I can't get my head around pthreads library and every time I run my program I encounter this error: Warning: PHP Startup: Unable to load dynamic library 'C:\php\ext\php_pthreads.dll' - The specified module could not be found.in Unknown on line 0 I followed every step needed: I've added the file pthreadVC2.dll in my "C:\php" folder I've added the file php_pthreads.dll in my "C:\php\ext"folder I've modified the file php.ini, enabling the extension:

Running CompletableFuture.thenAccept from the calling thread?

允我心安 提交于 2021-01-27 06:28:31
问题 I want to call CompletableFuture.supplyAsync() to delegate a blocking task to another thread. Once that task completes I would like for the CompletableFuture.thenAccept consumer to run in the context of the calling thread. For example: // Thread 1 CompletableFuture.supplyAsync(() -> { // Thread 2 return BlockingMethod(); }).thenAccept(( Object r) -> { // Thread 1 }); The following code suggests that CompletableFuture.thenAccept runs in its own thread; probably the same pool as

JavaFX Image Loading in Background and Threads

安稳与你 提交于 2021-01-27 06:11:32
问题 I thought this would be a simple question but I am having trouble finding an answer. I have a single ImageView object associated with a JavaFX Scene object and I want to load large images in from disk and display them in sequence one after another using the ImageView. I have been trying to find a good way to repeatedly check the Image object and when it is done loading in the background set it to the ImageView and then start loading a new Image object. The code I have come up with (below)

JavaFX Image Loading in Background and Threads

感情迁移 提交于 2021-01-27 06:11:05
问题 I thought this would be a simple question but I am having trouble finding an answer. I have a single ImageView object associated with a JavaFX Scene object and I want to load large images in from disk and display them in sequence one after another using the ImageView. I have been trying to find a good way to repeatedly check the Image object and when it is done loading in the background set it to the ImageView and then start loading a new Image object. The code I have come up with (below)

Python 3: How to submit an async function to a threadPool?

佐手、 提交于 2021-01-27 05:58:53
问题 I want to use both ThreadPoolExecutor from concurrent.futures and async functions. My program repeatedly submits a function with different input values to a thread pool. The final sequence of tasks that are executed in that larger function can be in any order, and I don't care about the return value, just that they execute at some point in the future. So I tried to do this async def startLoop(): while 1: for item in clients: arrayOfFutures.append(await config.threadPool.submit(threadWork, obj

Python 3: How to submit an async function to a threadPool?

我的梦境 提交于 2021-01-27 05:58:06
问题 I want to use both ThreadPoolExecutor from concurrent.futures and async functions. My program repeatedly submits a function with different input values to a thread pool. The final sequence of tasks that are executed in that larger function can be in any order, and I don't care about the return value, just that they execute at some point in the future. So I tried to do this async def startLoop(): while 1: for item in clients: arrayOfFutures.append(await config.threadPool.submit(threadWork, obj