concurrency

How accurate is the task scheduling of a ScheduledThreadPoolExecutor

╄→尐↘猪︶ㄣ 提交于 2020-06-14 05:59:28
问题 I was reading ScheduledThreadPoolExecutor JavaDoc and came across the following thing: Delayed tasks execute no sooner than they are enabled, but without any real-time guarantees about when, after they are enabled, they will commence . Tasks scheduled for exactly the same execution time are enabled in first-in-first-out (FIFO) order of submission. So, if I write something like this: ScheduledExecutorService ses = Executors.newScheduledThreadPool(4); //uses ScheduledThreadPoolExecutor

tbb:concurrent_hash_map<K,V>: sample code for Intel Threading Building Blocks (TBB)

冷暖自知 提交于 2020-06-13 05:06:19
问题 Looking for sample code to use tbb::concurrent_hash_map<K,V> from Intel Threading Building Blocks (TBB). I can insert, but I cannot seem to read the values back. The official Intel documentation appears to be somewhat lacking on the sample code side. Update The best docs are in "Pro TBB: C++ Parallel Programming with Threading Building Blocks" by Voss. Download this book for free (it's public domain). Ignore the Intel docs. They are essentially a collection of function signatures. 回答1: Intel

tbb:concurrent_hash_map<K,V>: sample code for Intel Threading Building Blocks (TBB)

谁都会走 提交于 2020-06-13 05:06:10
问题 Looking for sample code to use tbb::concurrent_hash_map<K,V> from Intel Threading Building Blocks (TBB). I can insert, but I cannot seem to read the values back. The official Intel documentation appears to be somewhat lacking on the sample code side. Update The best docs are in "Pro TBB: C++ Parallel Programming with Threading Building Blocks" by Voss. Download this book for free (it's public domain). Ignore the Intel docs. They are essentially a collection of function signatures. 回答1: Intel

What happens when reading or writing concurrently without a mutex

倖福魔咒の 提交于 2020-06-11 15:56:11
问题 In Go, a sync.Mutex or chan is used to prevent concurrent access of shared objects. However, in some cases I am just interested in the latest value of a variable or field of an object. Or I like to write a value and do not care if another go-routine overwrites it later or has just overwritten it before. Update: TLDR; Just don't do this. It is not safe. Read the answers, comments, and linked documents! Here are two variants good and bad of an example program, where both seem to produce

threadpool c++ implementation questions

妖精的绣舞 提交于 2020-06-10 21:24:20
问题 here and here , we can see similar threadpool implementations. my question is about function to add the task to threadpool, these are add and enqueue in projects above respectively. because these look very similar I'm posting a piece of one here (from second project) auto ThreadPool::enqueue(F&& f, Args&&... args) -> std::future<typename std::result_of<F(Args...)>::type> { using return_type = typename std::result_of<F(Args...)>::type; auto task = std::make_shared< std::packaged_task<return

threadpool c++ implementation questions

狂风中的少年 提交于 2020-06-10 21:15:05
问题 here and here , we can see similar threadpool implementations. my question is about function to add the task to threadpool, these are add and enqueue in projects above respectively. because these look very similar I'm posting a piece of one here (from second project) auto ThreadPool::enqueue(F&& f, Args&&... args) -> std::future<typename std::result_of<F(Args...)>::type> { using return_type = typename std::result_of<F(Args...)>::type; auto task = std::make_shared< std::packaged_task<return

Adding to a generic dictionary causes IndexOutOfRangeException

♀尐吖头ヾ 提交于 2020-06-09 10:59:20
问题 I'm using a dictionary inside of some Task. Logically I have set it up so that my Keys will never clash, though sometimes when I am adding to the dictionary I get this Exception. Index was outside the bounds of the array. at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add) at System.Collections.Generic.Dictionary`2.Add(TKey key, TValue value) at Rpc.<MapIntoRpc>b__4[T](Object x) in Rpc.cs:line 113 at System.Threading.Tasks.Task`1.InvokeFuture(Object

Why there are no concurrency keywords in Kotlin?

对着背影说爱祢 提交于 2020-06-09 07:19:05
问题 Why there are no keywords for synchronization/concurrency? So far my research gives me one solution, you wrap some high level classes and use them to handle concurrency. Given a project in pure Kotlin, what one shall do if there is a need for a small highly optimized component that handles concurrency etc? My impression is that Kotlin is an assisting language for Java, to write 90% of the code in Kotlin but have some java code that is not possible to express with Kotlin. Is this right? Is

Handle back-pressure in FixedThreadPool

戏子无情 提交于 2020-06-01 05:12:26
问题 How to deal with back-pressure in Java using thread pool? How to reject new tasks so there are no more than N submitted tasks. N - is the maximum number of allowed tasks in submission queue, which include new, running, paused (not finished) tasks. Use case Users submit calculation tasks that run for some time . Sometimes, there are so many users submitting tasks at the same time. How to reject new tasks if there are already N tasks submitted. In other words, the total number of submitted (not

Synchronization in java ForkJoinPool compute() method

♀尐吖头ヾ 提交于 2020-06-01 05:07:56
问题 in Java: The Complete Reference we read: In general, a ForkJoinTask should not use synchronized methods or synchronized blocks of code. Also, you will not normally want to have the compute( ) method use other types of synchronization, such as a semaphore Why should I avoid synchronizing in compute()? Is it still possible in some situation to use synchronization such as semaphore or synchronized? What other method should I use from java.util.concurrent to have scallable number of threads as in