lock-free

Does a lock-free queue “multiple producers-single consumer” exist for Delphi?

牧云@^-^@ 提交于 2019-12-04 00:58:51
I've found several implementations for single producer-single consumer, but none for multiple producer-single consumer. Does a lock-free queue for "multiple producers-single consumer" exist for Delphi? Lock-free queue from the OmniThreadLibrary supports multiple producers. You can use it separately from the threading library (i.e. you can use OtlContainers unit in any other framework). As the Daniele pointed below, there are two queues in the OmniThreadLibrary. The one in the OtlContainers supports multiple producers and multiple consumers while the "smarter" version in OtlComm (which is just

Lock-free queue

ぃ、小莉子 提交于 2019-12-03 22:46:03
Also I am doing a c implementation and currently have the structure of the queue: typedef struct queueelem { queuedata_t data; struct queueelem *next; } queueelem_t; typedef struct queue { int capacity; int size; queueelem_t *head; queueelem_t *tail; } queue_t; queue_t * queue_init(int capacity) { queue_t *q = (queue_t *) malloc(sizeof(queue_t)); q->head = q->tail = NULL; q->size = 0; q->capacity = capacity; return q; } int CompareAndExchange (void **a, void *comparand,void *new) { int success = 0; pthread_mutex_lock(&CE_MUTEX); if ((*a) != comparand) { (*a) = new; //return TRUE success = 1; }

What's the different between LinkedBlockingQueue and ConcurrentLinkedQueue?

限于喜欢 提交于 2019-12-03 16:16:05
I've read the blog, but i'm not sure whether his conclusion is correct : http://www.javacodegeeks.com/2010/09/java-best-practices-queue-battle-and.html#ixzz1seaiSLwp He said : As you can see from the provided performance results LinkedBlockingQueue achieved the best combined (adding and removing elements) performance results and should be your number one candidate for implementing producer – consumer schenarios. I wonder that, doen't it faster if i don't use lock in my code ? So why the LinkedBlockingQueue is faster than the lock-free Queue(ConcurrentLinkedQueue) ? Thanks !

Do I need a memory barrier for a change notification flag between threads?

好久不见. 提交于 2019-12-03 13:23:29
问题 I need a very fast (in the sense "low cost for reader", not "low latency") change notification mechanism between threads in order to update a read cache: The situation Thread W (Writer) updates a data structure ( S ) (in my case a setting in a map) only once in a while. Thread R (Reader) maintains a cache of S and does read this very frequently. When Thread W updates S Thread R needs to be notified of the update in reasonable time (10-100ms). Architecture is ARM, x86 and x86_64. I need to

Lock free & Thread-Safe IList<T> for .NET

纵然是瞬间 提交于 2019-12-03 07:20:34
问题 Is there a lock-free & thread-safe data structure that implements IList? Naturally by lock-free I mean an implementation that makes no use of locking primitives in .NET but rather uses interlocked operations / atomic operations to achieve thread safety... There isn't one, apparently under the concurrent data structures... Has anyone seen one floating around? I've seen a java one implemented in amino-cbbs, called LockFreeVector but nothing for .NET so far. Any ideas? 回答1: Well, I couldn't find

Is multiple-producer, single-consumer possible in a lockfree setting?

泪湿孤枕 提交于 2019-12-03 06:13:42
问题 I have a bunch of threads that are doing lots of communication with each other. I would prefer this be lock free. For each thread, I want to have a mailbox, where other threads can send it messages, (but only the owner can remove messages). This is a multiple-producer single-consumer situation. is it possible for me to do this in a lockfree / high performance matter? (This is in the inner loop of a gigantic simulation.) 回答1: Sure, if you have an atomic CompareAndSwap instruction: for (i = 0;

boost c++ lock-free queue vs shared queue

十年热恋 提交于 2019-12-03 05:15:39
问题 I'm quite new in multithreading programming, I just know the most common Producer-Consumer-Queue. I'm using the boost c++ libraries and I don't know if is better use boost::lockfree::queue or a wrapper class around std::queue that is using `mutex` and `condition_variable`. Where is better using lock free data structures and where is better is use a simple implementation based on `mutex` and `condition_variables`? 回答1: Try both in your app, see which performs best. Typically, polling a lock

Understanding CLR 2.0 Memory Model

巧了我就是萌 提交于 2019-12-03 05:11:29
问题 Joe Duffy, gives 6 rules that describe the CLR 2.0+ memory model (it's actual implementation, not any ECMA standard) I'm writing down my attempt at figuring this out, mostly as a way of rubber ducking, but if I make a mistake in my logic, at least someone here will be able to catch it before it causes me grief. Rule 1: Data dependence among loads and stores is never violated. Rule 2: All stores have release semantics, i.e. no load or store may move after one. Rule 3: All volatile loads are

Lock-free swap of two unique_ptr<T>

无人久伴 提交于 2019-12-03 04:07:48
问题 Swapping two unique_ptr s is not guaranteed to be threadsafe. std::unique_ptr<T> a, b; std::swap(a, b); // not threadsafe Since I need atomic pointer swaps and since I like the ownership handling of unique_ptr , is there a simple way to combine them both? Edit: If this is not possible, I am open for alternatives. I at least want to do something like this: threadshared_unique_ptr<T> global; void f() { threadlocal_unique_ptr<T> local(new T(...)); local.swap_content(global); // atomically for

How can I verify lock-free algorithms?

穿精又带淫゛_ 提交于 2019-12-03 02:46:08
问题 In theory, it should be possible to at least brute force a verification of a lock-free algorithm (there are only so many combinations of function calls intersecting). Are there any tools or formal reasoning processes available to actually prove that a lock-free algorithm is correct (ideally it should also be able to check for race conditions and the ABA problem as well)? Note: If you know a way to just prove one point (e.g. only prove that it is safe from the ABA problem) or a problem I haven