multithreading

How to force main thread to wait for all its child threads finish in Haskell

倖福魔咒の 提交于 2020-01-22 12:00:07
问题 In the following Haskell code, how to force main thread to wait till all its child threads finish. I could not able to use forkFinally as given in the section "Terminating the Program" here in this link: (http://hackage.haskell.org/package/base-4.7.0.2/docs/Control-Concurrent.html). I get desired result when using TMVar. But I want to do this with TVar. Please help. module Main where import Control.Monad import Control.Concurrent import Control.Concurrent.STM type TInt = TVar Int transTest ::

How to force main thread to wait for all its child threads finish in Haskell

白昼怎懂夜的黑 提交于 2020-01-22 11:59:46
问题 In the following Haskell code, how to force main thread to wait till all its child threads finish. I could not able to use forkFinally as given in the section "Terminating the Program" here in this link: (http://hackage.haskell.org/package/base-4.7.0.2/docs/Control-Concurrent.html). I get desired result when using TMVar. But I want to do this with TVar. Please help. module Main where import Control.Monad import Control.Concurrent import Control.Concurrent.STM type TInt = TVar Int transTest ::

What's the point of cache coherency?

梦想的初衷 提交于 2020-01-22 10:59:31
问题 On CPUs like x86, which provide cache coherency, how is this useful from a practical perspective? I understand that the idea is to make memory updates done on one core immediately visible on all other cores. This is a useful property. However, one can't rely too heavily on it if not writing in assembly language, because the compiler can store variable assignments in registers and never write them to memory. This means that one must still take explicit steps to make sure that stuff done in

What's the point of cache coherency?

北城以北 提交于 2020-01-22 10:58:01
问题 On CPUs like x86, which provide cache coherency, how is this useful from a practical perspective? I understand that the idea is to make memory updates done on one core immediately visible on all other cores. This is a useful property. However, one can't rely too heavily on it if not writing in assembly language, because the compiler can store variable assignments in registers and never write them to memory. This means that one must still take explicit steps to make sure that stuff done in

Is the explanation of relaxed ordering erroneous in cppreference?

限于喜欢 提交于 2020-01-22 10:50:11
问题 In the documentation of std::memory_order on cppreference.com there is an example of relaxed ordering: Relaxed ordering Atomic operations tagged memory_order_relaxed are not synchronization operations; they do not impose an order among concurrent memory accesses. They only guarantee atomicity and modification order consistency. For example, with x and y initially zero, // Thread 1: r1 = y.load(std::memory_order_relaxed); // A x.store(r1, std::memory_order_relaxed); // B // Thread 2: r2 = x

Can a shared lock on a std::shared_timed_mutex be upgraded to an exclusive lock?

别等时光非礼了梦想. 提交于 2020-01-22 10:38:30
问题 The new std::shared_timed_mutex allows for two types of locks: shared and exclusive. If one holds a shared lock, is there any way to atomically exchange it ("upgrade it") to an exclusive lock? In other words, given the following code, how can I avoid the non-atomic drop and re-lock? std::shared_timed_mutex m; //Guards a std::vector. m.lock_shared(); //Read from vector. (Shared lock is sufficient.) // ... //Now we want to write to the vector. We need an exclusive lock. m.unlock_shared(); // <-

Can a shared lock on a std::shared_timed_mutex be upgraded to an exclusive lock?

孤人 提交于 2020-01-22 10:38:09
问题 The new std::shared_timed_mutex allows for two types of locks: shared and exclusive. If one holds a shared lock, is there any way to atomically exchange it ("upgrade it") to an exclusive lock? In other words, given the following code, how can I avoid the non-atomic drop and re-lock? std::shared_timed_mutex m; //Guards a std::vector. m.lock_shared(); //Read from vector. (Shared lock is sufficient.) // ... //Now we want to write to the vector. We need an exclusive lock. m.unlock_shared(); // <-

Analyzing output of !threadpool and !threads in windbg

丶灬走出姿态 提交于 2020-01-22 09:08:46
问题 I have generated dumps on four servers and am analyzing the output of !threadpool and !threads. I noticed the roughly consistent following output: 0:024> !threadpool CPU utilization 0% Worker Thread: Total: 2 Running: 0 Idle: 2 MaxLimit: 200 MinLimit: 2 Work Request in Queue: 0 Number of Timers: 27 Completion Port Thread:Total: 2 Free: 0 MaxFree: 4 CurrentLimit: 2 MaxLimit: 200 MinLimit: 2 !threads -special ThreadCount: 32 UnstartedThread: 0 BackgroundThread: 19 PendingThread: 0 DeadThread:

Using ThreadStatic to replace expensive locals — good idea?

…衆ロ難τιáo~ 提交于 2020-01-22 08:57:24
问题 Update : as I should have expected, the community's sound advice in response to this question was to "measure it and see." chibacity posted an answer with some really nice tests that did this for me; meanwhile, I wrote a test of my own; and the performance difference I saw was actually so huge that I felt compelled to write a blog post about it. However, I should also acknowledge Hans's explanation that the ThreadStatic attribute is indeed not free and in fact relies on a CLR helper method to

Python multi-thread multi-interpreter C API

放肆的年华 提交于 2020-01-22 05:19:24
问题 I'm playing around with the C API for Python, but it is quite difficult to understand some corner cases. I could test it, but it seems a bug-prone and time consuming. So I come here to see if somebody has already done this. The question is, which is the correct way to manage a multi-thread with sub-interpreters, with no direct relation between threads and sub-interpreters? Py_Initialize(); PyEval_InitThreads(); /* <-- needed? */ _main = PyEval_SaveThread(); /* <-- acquire lock? does it matter