Questions tagged [atomicity]

In concurrent programming, an operation (or set of operations) is atomic, linearizable, indivisible or uninterruptible if it appears to the rest of the system to occur instantaneously. Atomicity is a guarantee of isolation from concurrent processes. Additionally, atomic operations commonly have a succeed-or-fail definition — they either successfully change the state of the system, or have no visible effect.

In concurrent programming, an operation (or set of operations) is atomic, linearizable, indivisible or uninterruptible if it appears to the rest of the system to occur instantaneously. Atomicity is a guarantee of isolation from concurrent processes. Additionally, atomic operations commonly have a succeed-or-fail definition — they either successfully change the state of the system, or have no visible effect.

Atomicity is commonly enforced by mutual exclusion, whether at the hardware level building on a cache coherency protocol, or the software level using semaphores or locks. Thus, an atomic operation does not actually occur instantaneously. The benefit comes from the appearance: the system behaves as if each operation occurred instantly, separated by pauses. Because of this, implementation details may be ignored by the user, except insofar as they affect performance. If an operation is not atomic, the user will also need to understand and cope with sporadic extraneous behaviour caused by interactions between concurrent operations, which by its nature is likely to be hard to reproduce and debug.

Source: Wikipedia

574 questions
115
votes
4 answers

reference assignment is atomic so why is Interlocked.Exchange(ref Object, Object) needed?

In my multithreaded asmx web service I had a class field _allData of my own type SystemData which consists of few List and Dictionary marked as volatile. The system data (_allData) is refreshed once in a while and I do it by creating another…
char m
  • 6,390
  • 14
  • 58
  • 96
112
votes
4 answers

Is file append atomic in UNIX?

In general, what can we take for granted when we append to a file in UNIX from multiple processes? Is it possible to lose data (one process overwriting the other's changes)? Is it possible for data to get mangled? (For example, each process is…
Lajos Nagy
  • 7,832
  • 11
  • 41
  • 52
99
votes
6 answers

When do I really need to use atomic instead of bool?

Isn't atomic redundant because bool is atomic by nature? I don't think it's possible to have a partially modified bool value. When do I really need to use atomic instead of bool?
user955249
84
votes
3 answers

What operations in Java are considered atomic?

What operations in Java are considered atomic?
robinmag
  • 15,600
  • 18
  • 51
  • 54
51
votes
3 answers

Django - Rollback save with transaction atomic

I am trying to create a view where I save an object but I'd like to undo that save if some exception is raised. This is what I tried: class MyView(View): @transaction.atomic def post(self, request, *args, **kwargs): try: …
Gocht
  • 8,493
  • 3
  • 31
  • 66
48
votes
4 answers

Is rename() atomic?

I am not being able to check this via experiments and could not gather it from the man pages as well. Say I have two processes, one moving(rename) file1 from directory1 to directory2. Say the other process running concurrently copies the contents…
Lipika Deka
  • 3,386
  • 6
  • 40
  • 54
46
votes
7 answers

Avoid duplicate POSTs with REST

I have been using POST in a REST API to create objects. Every once in a while, the server will create the object, but the client will be disconnected before it receives the 201 Created response. The client only sees a failed POST request, and tries…
geon
  • 6,983
  • 3
  • 31
  • 38
45
votes
4 answers

How are atomic operations implemented at a hardware level?

I get that at the assembly language level instruction set architectures provide compare and swap and similar operations. However, I don't understand how the chip is able to provide these guarantees. As I imagine it, the execution of the instruction…
Alexander Duchene
  • 877
  • 1
  • 9
  • 14
35
votes
12 answers

In C is "i+=1;" atomic?

In C, is i+=1; atomic?
Crazy Chenz
  • 10,877
  • 12
  • 44
  • 57
34
votes
9 answers

Pop multiple values from Redis data structure atomically?

Is there a Redis data structure, which would allow atomic operation of popping (get+remove) multiple elements, which it contains? There are well known SPOP or RPOP, but they always return a single value. Therefore, when I need first N values from…
Pavel S.
  • 10,292
  • 14
  • 68
  • 108
33
votes
5 answers

Atomic properties vs thread-safe in Objective-C

In most of the discussions I've read, it indicates that making a property atomic does not guarantee it to be thread-safe, it just guarantees that the value returned won't be garbage as a result of one object writing to it and another trying to read…
Doug Smith
  • 27,683
  • 54
  • 189
  • 363
31
votes
6 answers

Atomic Operations and multithreading

Recently I was reading a tutorial, in that I came across a statement that says.. "The Java language specification guarantees that reading or writing a variable is an atomic operation(unless the variable is of type long or double). Operations…
MaheshVarma
  • 1,982
  • 7
  • 31
  • 54
28
votes
1 answer

what is "failure atomicity" used by J bloch and how its beneficial in terms of immutable object?

just came across below statement as benefit of immutable object Immutable object always have “failure atomicity” (a term used by Joshua Bloch) : if an immutable object throws an exception, it’s never left in an undesirable or…
Bhargav Modi
  • 2,497
  • 3
  • 26
  • 46
27
votes
2 answers

compare and swap vs test and set

Could someone explain to me the working and differences of above operations in multi-threading?
Tony The Lion
  • 57,181
  • 57
  • 223
  • 390
27
votes
2 answers

Haskell: How does 'atomicModifyIORef' work?

Can someone explain how atomicModifyIORef works? In particular: (1) Does it wait for a lock, or optimistically try and retry if there's contention (like TVar). (2) Why is the signature of atomicModifyIORef different to the signature of modifyIORef?…
Clinton
  • 20,364
  • 13
  • 59
  • 142
1
2 3
38 39