Related Tags

c

# What is ATOMIC_WCHAR_T_LOCK_FREE in C?

Abdul Monum

ATOMIC_WCHAR_T_LOCK_FREE is a macro constant defined in the <stdatomic.h> header file in the C11 standard. ATOMIC_WCHAR_T_LOCK_FREE is relative to the type wchar_t but has an additional atomic property. Reading or writing an atomic type happens as a single unit of work, and therefore atomic types are guaranteed to have no race conditions when accessed by multiple threads.

The macro takes on the value $0$, $1$, or $2$ depending on the lock-free property type:

• $0$ defines that the type is never lock-free
• $1$ defines that the type is sometimes lock-free
• $2$ defines that the type is always lock-free

NOTE: wchar_t type is known as a wide string that uses characters from the Unicode character set, where each character is typically of 2 bytes.

## Lock-free programming

To ensure concurrency, Lock-free programming is an alternative paradigm to mutex locks and binary semaphores. Instead of using locking mechanisms to block threads from accessing data, lock-free programming allows atomic operations on the data using a transactional memory model.

## Transactional memory model

The transactional memory model bunches up a series of memory accesses and implements them at once as a transaction, which is similar to how transactions in databases work.

Lock-free programming is non-blocking, which allows lock-free programs to access shared resources without blocking other threads and avoiding race conditions. The non-blocking property of lock-free programming carries many performance advantages over mutex locks because concurrent access to resources is not blocked by other threads accessing the same data.

RELATED TAGS

c

CONTRIBUTOR

Abdul Monum