Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

c

What is ATOMIC_BOOL_LOCK_FREE macro in C?

Muhammad Ashir

ATOMIC_BOOL_LOCK_FREE is a macro defined in the C11 atomic library.

The macro takes on the value 00, 11, or 22 depending on whether the type is lock-free:

  • 00 defines that the type is never lock-free
  • 11 defines that the type is sometimes lock-free
  • 22 defines that the type is always lock-free

Lock-free programming

Lock-free programming can be used alternatively to the mutex and semaphores for concurrent. Instead of using locking mechanisms to block threads from accessing data or putting them to sleep (as is the case with mutex), lock-free programming allows atomic operations on the data using a transactional memory model.

Transactional memory model

The transactional memory model works by bunching up a series of memory accesses and implementing them at once as a transaction. This 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 introducing 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

Muhammad Ashir
Copyright ©2022 Educative, Inc. All rights reserved
RELATED COURSES

View all Courses

Keep Exploring