##master-page:CategoryTemplate ##master-date:Unknown-Date #format wiki #language en = Atomic Operations = '''Include File(s):''' [[http://hg.libsdl.org/SDL/file/default/include/SDL_atomic.h|SDL_atomic.h]] <> == Introduction == This category contains functions for handling atomic operations. /!\ ''IMPORTANT'': . 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: * [[SDL_AtomicLock]]() * [[SDL_AtomicUnlock]]() * [[SDL_AtomicIncRef]]() * [[SDL_AtomicDecRef]]() You can find out a little more about lockless programming and the subtle issues that can arise here: http://msdn.microsoft.com/en-us/library/ee418650%28v=vs.85%29.aspx There's also lots of good information here: http://www.1024cores.net/home/lock-free-algorithms http://preshing.com/ 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 following is included on SDL_AtomicLock and SDL_AtomicTryLock. Any changes between these comments will be reflected on those pages. Please use caution when editing. Start Include here. 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. ##End Include here ##Remove this line and the ## below to use this markup if it becomes relevant to this category ##== Enumerations == ##<> == Structures == <> == Functions == <> ---- CategoryCategory