Sponsored Content
Top Forums Programming pthread_mutex_lock in ANSI C vs using Atomic builtins of GCC Post 302448272 by Corona688 on Wednesday 25th of August 2010 03:48:41 PM
Old 08-25-2010
Yes, the pthread solution more than sufficiently protects it. (A pthread_rwlock would let readers operate at the same time and only block them for writes.)

If the gcc atomic operations are truly atomic, getva shouldn't ever return garbage.
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Convert file from Unix - ANSI to PC - ANSI

Hi, I am creating a file in Unix using a shell script. The file is getting created in the Unix - ANSI format. My requirement is to convert it to the PC - ANSI format. Can anyone tell me how to do this? Thanks, Sunil (0 Replies)
Discussion started by: ssmallya
0 Replies

2. Programming

pthread_rwlock_lock vs pthread_mutex_lock

I have been wondering what the difference between pthread_rwlock_lock and pthread_mutex_lock is. Both these routines acquire an exclusive rw lock on an enclosed region. So I performed a simple experiment in which I execute both these routines multiple times in a loop. Here are the results:... (1 Reply)
Discussion started by: kmehta
1 Replies

3. Programming

Interesting issue with pthread_mutex_lock and siglongjmp in AIX 5.3 (and no other OS)

Executive summary: Code (posted below) cores in AIX 5.3, despite being compiled and run successfully on several other operating systems. Code is attempting to verify that pthread_mutex_lock can be successfully aborted by siglongjmp. I do not believe this is an unreasonable requirement. If... (1 Reply)
Discussion started by: DreamWarrior
1 Replies

4. Shell Programming and Scripting

program name and function name builtins

Hi Is there a way to get the program/script name or function name usng built ins. Like in many languages arg holds the program name regards (2 Replies)
Discussion started by: xiamin
2 Replies

5. Programming

why the implementatoin of Bakery algorithm in ANSI C does not work in ANSI C

I follow the description of wiki (Lamport's bakery algorithm - Wikipedia, the free encyclopedia), then implement that algorithm in C, but it doesn't work, Starving is still here, is the implementation worry? Only print out: Thread ID: 0 START! Thread ID: 0 END! Thread ID: 0 START!... (2 Replies)
Discussion started by: sehang
2 Replies

6. UNIX for Advanced & Expert Users

Writing Custom Builtins for KSH93

I am looking to create some ksh93 extensions using the custom builtin feature. I can successfully create a builtin function, load it using the builtin -f command and get an output. However, I want to get/set values of KSH variables from within my built-in. For example, lets say I am creating... (2 Replies)
Discussion started by: a_programmer
2 Replies

7. UNIX for Dummies Questions & Answers

Why does /bin contain binaries for builtins?

Why do shell builtins like echo and pwd have binaries in /bin? When I do which pwd, I get the one in /bin. that means that I am not using the builtin version? What determines which one gets used? Is the which command a definitive way to determine what is being run when I enter pwd? (16 Replies)
Discussion started by: glev2005
16 Replies

8. Programming

Using ANSI color codes in gcc compiled program

I have put some yellow color codes and works well. I call the funstion using print_usage(stderr, 0); I would like to know if there is any way, to store the ansi color codes in variables and then call them inside fprintf. Or have a format followed by the strings I want to output. ... (5 Replies)
Discussion started by: kristinu
5 Replies

9. UNIX for Dummies Questions & Answers

Shell and bash builtins...

Not sure if this is the right forum but I have collated a listing of shell and bash builtins. Builtins is a loose word and may include the '/bin' drawer/folder/directory but NOT any others in the path list. In the case of my Macbook Pro, OSX 10.7.5 the enabled internals is also listed... ... (1 Reply)
Discussion started by: wisecracker
1 Replies
stdatomic(3)						   BSD Library Functions Manual 					      stdatomic(3)

NAME
ATOMIC_VAR_INIT, atomic_init, atomic_load, atomic_store, atomic_exchange, atomic_compare_exchange_strong, atomic_compare_exchange_weak, atomic_fetch_add, atomic_fetch_and, atomic_fetch_or, atomic_fetch_sub, atomic_fetch_xor, atomic_is_lock_free -- type-generic atomic opera- tions SYNOPSIS
#include <stdatomic.h> _Atomic(T) v = ATOMIC_VAR_INIT(c); _Atomic T v = ATOMIC_VAR_INIT(c); void atomic_init(_Atomic(T) *object, T value); T atomic_load(_Atomic(T) *object); T atomic_load_explicit(_Atomic(T) *object, memory_order order); void atomic_store(_Atomic(T) *object, T desired); void atomic_store_explicit(_Atomic(T) *object, T desired, memory_order order); T atomic_exchange(_Atomic(T) *object, T desired); T atomic_exchange_explicit(_Atomic(T) *object, T desired, memory_order order); _Bool atomic_compare_exchange_strong(_Atomic(T) *object, T *expected, T desired); _Bool atomic_compare_exchange_strong_explicit(_Atomic(T) *object, T *expected, T desired, memory_order success, memory_order failure); _Bool atomic_compare_exchange_weak(_Atomic(T) *object, T *expected, T desired); _Bool atomic_compare_exchange_weak_explicit(_Atomic(T) *object, T *expected, T desired, memory_order success, memory_order failure); T atomic_fetch_add(_Atomic(T) *object, T operand); T atomic_fetch_add_explicit(_Atomic(T) *object, T operand, memory_order order); T atomic_fetch_and(_Atomic(T) *object, T operand); T atomic_fetch_and_explicit(_Atomic(T) *object, T operand, memory_order order); T atomic_fetch_or(_Atomic(T) *object, T operand); T atomic_fetch_or_explicit(_Atomic(T) *object, T operand, memory_order order); T atomic_fetch_sub(_Atomic(T) *object, T operand); T atomic_fetch_sub_explicit(_Atomic(T) *object, T operand, memory_order order); T atomic_fetch_xor(_Atomic(T) *object, T operand); T atomic_fetch_xor_explicit(_Atomic(T) *object, T operand, memory_order order); _Bool atomic_is_lock_free(const _Atomic(T) *object); DESCRIPTION
The header <stdatomic.h> provides type-generic operations on atomic operations. Atomic variables are declared using the _Atomic() type specifier or the _Atomic type qualifier. Such variables are not type-compatible with their non-atomic counterparts and may have different alignment. Operations on atomic variables that do not use the atomic_() interfaces, including compound assignment operations, will behave as if the non-_explicit() versions of those interfaces had been used. The atomic_init() operation initializes the atomic variable object with value. Atomic variables can be initialized while being declared using ATOMIC_VAR_INIT(). The atomic_load() operation returns the value of atomic variable object. The atomic_store() operation sets the atomic variable object to the desired value. The atomic_exchange() operation combines the behaviour of atomic_load() and atomic_store(). It sets the atomic variable object to the desired value and returns the original contents of the atomic variable. The atomic_compare_exchange_strong() operation stores the desired value into atomic variable object, but only if the atomic variable is equal to the expected value. Upon success, the operation returns true. Upon failure, the expected value is overwritten with the contents of the atomic variable and false is returned. The atomic_compare_exchange_weak() operation is identical to atomic_compare_exchange_strong(), but is allowed to fail even if atomic variable object is equal to the expected value. When an atomic_compare_exchange() operation is in a loop, the weak version will yield better perfor- mance on some platforms. When atomic_compare_exchange_weak() would require a loop and atomic_compare_exchange_strong() would not, the strong version is preferable. The atomic_fetch_add() operation adds the value operand to atomic variable object and returns the original contents of the atomic variable. The atomic_fetch_and() operation applies the and operator to atomic variable object and value operand and stores the result into object, while returning the original contents of the atomic variable. The atomic_fetch_or() operation applies the or operator to atomic variable object and value operand and stores the result into object, while returning the original contents of the atomic variable. The atomic_fetch_sub() operation subtracts the value operand from atomic variable object and returns the original contents of the atomic variable. The atomic_fetch_xor() operation applies the xor operator to atomic variable object and value operand and stores the result into object, while returning the original contents of the atomic variable. The atomic_is_lock_free() operation returns whether atomic variable object uses locks to implement atomic operations. MEMORY ORDER
C11 defines a memory model that may allow for the reordering of operations in the absence of fences or explicit memory ordering operations. The non-_explicit() interfaces use the strictest available memory order: sequential consistency. The _explicit() interfaces allow for config- uration of the memory order operation which is present. The types of available memory order operations are explained in more detail in ISO/IEC 9899:2011 (``ISO C11''). The order parameter of the _explicit() interfaces can have one of the following values: memory_order_relaxed Operation does not order memory. memory_order_consume Performs a consume operation. memory_order_acquire Performs an acquire operation. memory_order_release Performs a release operation. memory_order_acq_rel Performs both an acquire and a release operation. memory_order_seq_cst Provides sequential consistency. SEE ALSO
atomic(3), pthread(3) STANDARDS
These interfaces conform to ISO/IEC 9899:2011 (``ISO C11''). BSD
December 27, 2011 BSD
All times are GMT -4. The time now is 08:17 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy