Questions tagged [atomic]

An atomic operation is one which can be considered, from the perspective of the computing context in which it occurs, to be executed in a single step. Atomic operations either succeed entirely or fail, with no intermediate states.

Filter by
Sorted by
Tagged with
-2
votes
0answers
35 views

C++ ringbuffer with cas [on hold]

This a sample unlock ringbuffer with cas.But still with bugs in put / get. One known bug is multi readers will make m_rear step over m_front then block or coredump. Can someone help me to fix it? ...
4
votes
0answers
51 views

C++14 AtomicRoundRobinPool for sharing a pool of keys

The idea here is that we have some resource that is relatively very expensive to generate, but once we have a bunch of them in a pool, we can keep reusing them instead of generating new ones. "HTTP ...
1
vote
1answer
70 views

A minimalistic kind of read-copy-update class

This is a very simple read-copy-update (RCU)-inspired synchronization class: ...
8
votes
3answers
423 views

C++ lock free, single producer, single consumer queue

Assumptions for use: push() will only ever be called by a single thread. pop() will only ever be called by a single thread. Requirements: push() needs to be as fast as possible. Requirements are ...
1
vote
1answer
63 views

Passing objects atomically across threads without locks or data races for audio synchronization

I am learning about one of the hardest parts of Audio development: the synchronization between the audio thread and the GUI thread. Per the discussion here https://forum.juce.com/t/timur-doumler-...
2
votes
0answers
370 views

A multithreaded, growable vector with immutable elements, which has wait-free reads

I wrote a small vector with a few lines of unsafe Rust. The idea is to have a vector, which can be read from simultaneously, but it needs the ability to grow. To realize that, the storage is ...
3
votes
1answer
59 views

Concurrent Data Manager with minimal synchronization

So I have my own library to organize advanced critical sections at GitHub. It's based on the ResourceDataStorage class which is responsible for creating, storing and clearing resource records. I've ...
2
votes
0answers
106 views

Lock-free statically allocated async-interrupt-safe multi-consumer double buffer

I have a single threaded embedded system with nested interrupts. A writer interrupt will periodically update some global data structure with data. Reader interrupts / calls from main thread will read ...
11
votes
1answer
2k views

Lock-free atomic shared pointer in C++14

I'm trying to write a lock-free implementation for atomic shared pointer. Basically, there are two class templates shared_ptr and ...
6
votes
2answers
71 views

Simple atomic pseudo-random number generation

I like to use a single global PRNG in my c programs (similar to Javascript's Math.random) because it simplifies things and the unpredictable nature of a global is ...
1
vote
1answer
2k views

A simple implementation of the producer/consumer pattern

Consider this class that consumes some items and handles them with the provided handler function: ...
4
votes
0answers
81 views

Swift framework that facilitates making atomic changes to several objects at a time

For the purposes of an app I work on I have created a separate framework that abstracts away the mechanism of making atomic changes to the complex object structures. Each class that has to ...
1
vote
0answers
180 views

Get/Set the value in the cache using the AtomicReference in Java

I have this code which gets and sets the data in the cache using the synchronized block. I want to know if is there is any way by which I can remove the synchronized...
2
votes
0answers
327 views

Concurrent ObjectPool using ConcurrentLinkedQueue

Main ObjectPool Class: It uses atomic operations and a concurrent linked queue to achieve the best performance compared to Apache commons pool. I want to make sure there are no concurrency issues even ...
3
votes
1answer
219 views

Double checked locking with shared_ptr<>

I have an unordered_map<int, std::shared_ptr<foo>> into which I want to lazily create the instances of foo based on ...
5
votes
2answers
804 views

Atomic floating-point addition

I need to be able to atomically add a 32-bit floating point value to a location in memory. Here is what I came up with. While the code is Windows-specific, I'll extend it with Linux support using <...
2
votes
1answer
41 views

Stored procedure to swap account holders

I'm doing an exercise, and would like to know if what I'm doing is correct and follows the correct structure for rollback in case a transaction fails. I would like to know as well if my ...
1
vote
0answers
56 views

Block a partcular machine for a particular period of time interval after x failure

This is an extension to this question I am working on a library which makes Http call to my service. I have below two requirements: If my service machine doesn't respond back (there is a socket ...
3
votes
1answer
141 views

Async safe threadpool

I'm trying the write a threadpool that can safely be added inside a signal handler or in code forked by multithreaded code. Are there any corner cases that would cause this code to fail? What could be ...
11
votes
1answer
2k views

Copyable Atomic

I find it pretty annoying that c++11 atomics can't be copied. The reasons for this have been discussed e.g. here and I don't want to argue about them now. However, I find myself repeatedly in ...
2
votes
0answers
135 views

Controller method to add a product, stored across three database tables

I have some questions on how I can improve this "add" action method in a controller. Using a single form, the user can upload a product to be displayed on the site. A Product is composed of three ...
3
votes
2answers
100 views

Single reader - multiple writer waitable lock-free unreliably ordered stack

The main body of code is located here. In the code linted_error is a platform specific type for error codes. As well, as an optimization the code can use Linux ...
5
votes
1answer
103 views

Lock implementation using atomics

I was recently given an interview and was asked to write my own lock implementation using atomics, but not necessary reentrant. I didn't answer the question, but at home, I wrote this code. Please ...
7
votes
1answer
432 views

Fast non-fair semaphore

This is a simple non-fair semaphore implementation using Java atomic objects. It currently performs a little over twice as fast as java.util.concurrent.Semaphore on ...
3
votes
3answers
383 views

SPSC Wait Free Ring Buffer for incoming messages

This is for a single producer and single consumer wait free ring buffer. The writes need to be wait free for sure. It pre-allocates messages slots and uses a claim strategy to capture a buffer for ...
2
votes
1answer
245 views

Unreliable shared memory circular buffer with read-only consumer

This code is slightly platform dependent but should be pretty easy to port. The goal with this code was to create a circular buffer where the consumer could be limited to read-only access of the ...
3
votes
1answer
765 views

Transaction.atomic with continuations

I have a view that looks like this: ...
4
votes
1answer
73 views

Adding hostname to block list after x consecutive failures in multithreading application

I am using Callable in my code which will be called by multiple threads as shown below. Given a user id in DataKey object, I will find out what are the ...
6
votes
1answer
3k views

Lockless multi user, multi consumer FIFO queue using C++11

One of the features that is missing from C++11 are lockless queues. Therefore I have decided to write one myself. A few remarks: I know the code isn't technically lockless. However the lock is only ...
6
votes
1answer
1k views

C++ concurrency library

I started a C++11 library of concurrency primitives in order to study and compare their performance; provide high-quality implementation of those to use in my projects. Its main target platform is ...
5
votes
1answer
4k views

Lock-free ringbuffer with multiple readers in C++11

Basic Info I needed a lock-free ringbuffer with multiple readers (but one writer). However, I did not want the writer to check all readers every time in order to prevent an overrun. Thus, I decided ...
6
votes
1answer
603 views

General Batched Job Runner

This question is inspired by: Generic Task Scheduler where the problem is to run tasks on a scheduled basis, in parallel, and have individual timeouts for each job. For example, consider this use-...
7
votes
3answers
355 views

Having full atomicity against all the threads without impacting performance or throughputs

I am working on a project in which I construct a URL with a valid hostname (but not a blocked hostname) and then execute that URL using RestTemplate from my main ...
12
votes
1answer
4k views

Replacement for commit_on_success

I am porting an application from django 1.4.5 to django 1.6.1. I found that commit_on_success has been deprecated. Moreover I found specific incompatibilities when ...
7
votes
1answer
507 views

Concurrent queue

I recently wrote a concurrent, mutex-less (but not lockfree) queue and wanted to know if it is actually correct, and if there are any particular improvements I could make: ...
6
votes
3answers
4k views

Executing a URL using RestTemplate

I am working on a project in which I construct a URL with a valid hostname (but not a blocked hostname) and then execute that URL using RestTemplate from my main ...
7
votes
2answers
593 views

Constructing a URL for execution

I am working on a project in which I construct a URL with a valid hostname (but not a blocked hostname) and then execute that URL using RestTemplate from my main ...
4
votes
1answer
481 views

Constructing a URL for execution using RestTemplate

I am working on a project in which I construct a URL with a valid hostname (but not a blocked hostname) and then execute that URL using RestTemplate from my main ...
6
votes
2answers
1k views

Lock for preventing concurrent access in client data

I am trying to implement lock by which I don't want to have reads from happening whenever I am doing a write. Here is my ClientData class in which I am using ...
2
votes
1answer
260 views

(nearly) lock-free job queue of dynamic size (multiple read/write)

Warning: the code below is NOT multi read/write! It'l work fine as long as you don't have multiple writes OR don't require resize. But with multiple writers, the code can enter a deadlock state. I'm ...
5
votes
1answer
471 views

lock-free job queue without size restriction (multiple read/write)

I've since come up with an improved version, which isn't technically lock-free, but might be as close as you can get (nearly) lock-free job queue of dynamic size (multiple read/write) code below is ...
11
votes
1answer
4k views

Play some sine waves with SDL2

Runs smoothly, however valgrind is showing "possibly lost: 544 bytes in 2 blocks". This is my first time doing a lot of things here so I might be making multiple mistakes. Please let me know if ...
15
votes
1answer
5k views

Lock-free multiple-consumer multiple-producer queue

The code below implements an intrusive lock-free queue that supports multiple concurrent producers and consumers. Some features: Producers and consumers work on separate ends of the queue most of ...
2
votes
2answers
3k views

Lock-Free Ring Implementation

I am wondering if someone can take a look at my lock-free, circular ring implementation which I use to implement a background logger. The CircularRing pre-...
8
votes
2answers
14k views

atomic_queue - thread-safe and lock-free implementation of the FIFO data structure pattern

please review my implementation of a FIFO data structure that guarantees thread-safe access without locking. I removed the license header block and all Doxygen comments. The original version (along ...
17
votes
2answers
2k views

O(1) lock free container

This is a lock-free Container class. By Container I mean it will hold objects for iteration at a later time. To achieve \$O(1)\$ ...
4
votes
3answers
218 views

Win7 atomic access class

I have a simple atomic access class designed to work with Windows threads: ...