This is new wiki software and old wiki content. It's a work in progress!
Here's the explanation.
Be gentle, report bugs, leave feedback on pages, or just edit them yourself! Thanks!

SDL Wiki

Atomic Operations

Include File(s): SDL_atomic.h


This category contains functions for handling atomic operations.


If you are not an expert in concurrent lockless programming, you should only be using the atomic lock and reference counting functions in this file. In all other cases you should be protecting your data structures with full mutexes. Seriously, here be dragons!

"Safe" functions to use are:

You can find out a little more about lockless programming and the subtle issues that can arise here:

There's also lots of good information here:

These operations may or may not actually be implemented using processor specific atomic operations. When possible they are implemented as true processor specific atomic operations. When that is not possible the are implemented using locks that do use the available atomic operations.

All of the atomic operations that modify memory are full memory barriers.

Atomic Locks

The atomic locks are efficient spinlocks using CPU instructions, but are vulnerable to starvation and can spin forever if a thread holding a lock has been terminated. For this reason you should minimize the code executed inside an atomic lock and never do expensive things like API or system calls while holding them.

/!\ The atomic locks are not safe to lock recursively.


<<FullSearchCached(category:CategoryAtomic CategoryStruct -title:SGStructures)>>


<<FullSearchCached(category:CategoryAtomic -CategoryEnum -CategoryStruct -title:SGFunctions)>>


[ edit | delete | history | feedback | raw ]

[ front page | index | search | recent changes | git repo | offline html ]

All wiki content is licensed under Creative Commons Attribution 4.0 International (CC BY 4.0).
Wiki powered by ghwikipp.