FAQ Database Discussion Community


Performance comparison between compare-and-swap and blocking algorithm

java,concurrency,blocking,lock-free
I have a ConcurrentLinkedQueue that I use as the underlying datastructure. On every put call, I add a unique incremented value to the list. I have both the synchronized and compare-and-swap versions of this method. When I have few threads (e.g., 5) and doing 10 million puts in all, I...

Go atomic and memory order

c++11,go,atomic,lock-free
I am porting a lock free queue from c++11 to go and i came across things such as auto currentRead = writeIndex.load(std::memory_order_relaxed); and in some cases std::memory_order_release and std::memory_order_aqcuire also the equivelent for the above in c11 is something like unsigned long currentRead = atomic_load_explicit(&q->writeIndex,memory_order_relaxed); the meaning of those is...

How to update 2 objects atomically in a lock-free manner?

java,multithreading,atomic,lock-free,compare-and-swap
I'm working on class that implements hash-code based atomic locking by multiple objects. The main purpose is to unpark a waiter thread as soon as all required locks become available, thus reducing overall waiting time. Its lockAndGet(List objects) returns a single "composite lock" that involves all listed objects. After the...

Implementation detail of lock-free single-writer multi-reader list

c++,algorithm,lock-free
I am attempting to understand the implementation of the single-writer multi-reader doubly linked list found in http://web.cecs.pdx.edu/~walpole/class/cs510/papers/11.pdf on page 10 of the pdf (or 500 of the journal article). I simply cannot understand how the Insert and Delete functionality is working My understanding of it is A double pointer is...

Lock-free thread-safe lazy initialization

java,multithreading,lazy-initialization,lock-free,wait-free
To perform lock-free and wait-free lazy initialization I do the following: private AtomicReference<Foo> instance = new AtomicReference<>(null); public Foo getInstance() { Foo foo = instance.get(); if (foo == null) { foo = new Foo(); // create and initialize actual instance if (instance.compareAndSet(null, foo)) // CAS succeeded return foo; else //...

How should boost::lockfree::spsc_queue's read_available and write_available be used?

c++,boost,lock-free
Boost documentation for spsc_queue says: read_available(): Thread-safe and wait-free, should only be called from the producer thread write_available(): Thread-safe and wait-free, should only be called from the consumer thread I would expect the most common use case to be just the other way around: producer thread (thread writing data to...

protect two variables with atomic in a multi-threading environement

c++,atomic,lock-free
//Thread 1 std::uint64_t getAndResetProcessingTimeInMicro() { auto value = m_cumulatedProcessingTimeCount.load(boost::memory_order_acquire); if (value == 0) return 0; auto processingTime = m_cumulatedProcessingTime.load(boost::memory_order_relaxed); resetProcessingTimeInMicro(); return processingTime / value; } //Thread 2 void addProcessingTimeInMicro(std::uint64_t processedTime) { m_cumulatedProcessingTime.fetch_add(processedTime, boost::memory_order_relaxed); //ctxt switch here //-----HERE------...

Non blocking way of adding a work item to array or list

c++,c++11,threadpool,future,lock-free
Edit: I now have finished my queue (overcoming the problem described below, and more). For those interested it can be found here. I'd be happy to hear any remarks:). Please note the queue isn't just a work item queue, but rather a template container which of course could be instantiated...

Lock Free Bounded Stack C++11 atomics

c++,multithreading,c++11,stack,lock-free
I was thinking about using very basic bounded (preallocated) stack to keep track of my threads ids in correct LIFO order. So i was wondering if my implementation is thread safe: // we use maximum 8 workers size_t idle_ids_stack[8]; // position current write happening at std::atomic_uint_fast8_t idle_pos(0); // this function...