Sponsored Content
Full Discussion: Atomic Operations
Operating Systems Linux Atomic Operations Post 302722981 by jim mcnamara on Monday 29th of October 2012 07:14:44 AM
Old 10-29-2012
This discusses atomic_t and operations that are atomic.
Code:
i++

is atomic, possibly depending on the datatype of i.

Atomic Operations
 

4 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Is `mv dir dir2` atomic ?

if I rename a dir mv dir dir2 Is this operation atomic? Suppose there 100 files in dir, does linux rename them one by one or at once? In other words, is there a time at which both dir and dir2 exist, with dir has, say 30 files and dir2 has the rest 70 files? (4 Replies)
Discussion started by: meili100
4 Replies

2. Programming

Atomic lock file creation

Hello, I need to implement a locking system in C. My problem is how to make the check if the lock file exist and locking it atomic operation. I want to make something like this: FILE* lock_fname; lock_fname = fopen ( "file.lock", "r"); /*check if file exsists*/ if (lock_fname) { fclose... (7 Replies)
Discussion started by: tsurko
7 Replies

3. Programming

Atomic Read and Write with stdio

hi guys. can we use fread and fwrite with pipes to write data more than PIPE_BUF atomically since they lock FILE object until I/O operation finish? (1 Reply)
Discussion started by: majid.merkava
1 Replies

4. UNIX for Dummies Questions & Answers

system calls and atomic operation

Are system calls atomic operations? Is a system call can be interrupted? (2 Replies)
Discussion started by: vistastar
2 Replies
ATOMIC_OPS(3)						   BSD Library Functions Manual 					     ATOMIC_OPS(3)

NAME
atomic_ops -- atomic memory operations SYNOPSIS
#include <sys/atomic.h> DESCRIPTION
The atomic_ops family of functions provide atomic memory operations. There are 7 classes of atomic memory operations available: atomic_add(3) These functions perform atomic addition. atomic_and(3) These functions perform atomic logical ``and''. atomic_cas(3) These functions perform atomic compare-and-swap. atomic_dec(3) These functions perform atomic decrement. atomic_inc(3) These functions perform atomic increment. atomic_or(3) These functions perform atomic logical ``or''. atomic_swap(3) These functions perform atomic swap. Synchronization Mechanisms Where the architecture does not provide hardware support for atomic compare and swap (CAS), atomicity is provided by a restartable sequence or by a spinlock. The chosen method is not ordinarily distinguishable by or visible to users of the interface. The following architectures can be assumed to provide CAS in hardware: alpha, amd64, i386, powerpc, powerpc64, sparc64. Scope and Restrictions If hardware CAS is available, the atomic operations are globally atomic: operations within a memory region shared between processes are guar- anteed to be performed atomically. If hardware CAS is not available, it may only be assumed that the operations are atomic with respect to threads in the same process. Additionally, if hardware CAS is not available, the atomic operations must not be used within a signal handler. Users of atomic memory operations should not make assumptions about how the memory access is performed (specifically, the width of the memory access). For this reason, applications making use of atomic memory operations should limit their use to regular memory. The results of using atomic memory operations on anything other than regular memory are undefined. Users of atomic memory operations should take care to modify any given memory location either entirely with atomic operations or entirely with some other synchronization mechanism. Intermixing of atomic operations with other synchronization mechanisms for the same memory loca- tion results in undefined behavior. Visibility and Ordering of Memory Accesses If hardware CAS is available, stores to the target memory location by an atomic operation will reach global visibility before the operation completes. If hardware CAS is not available, the store may not reach global visibility until some time after the atomic operation has com- pleted. However, in all cases a subsequent atomic operation on the same memory cell will be delayed until the result of any preceeding oper- ation has reached global visibility. Atomic operations are strongly ordered with respect to each other. The global visibility of other loads and stores before and after an atomic operation is undefined. Applications that require synchronization of loads and stores with respect to an atomic operation must use memory barriers. See membar_ops(3). Performance Because atomic memory operations require expensive synchronization at the hardware level, applications should take care to minimize their use. In certain cases, it may be more appropriate to use a mutex, especially if more than one memory location will be modified. SEE ALSO
atomic_add(3), atomic_and(3), atomic_cas(3), atomic_dec(3), atomic_inc(3), atomic_or(3), atomic_swap(3), membar_ops(3) HISTORY
The atomic_ops functions first appeared in NetBSD 5.0. BSD
April 14, 2010 BSD
All times are GMT -4. The time now is 11:25 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy