Wiki Page Content

Differences between revisions 10 and 11
Revision 10 as of 2011-01-28 20:05:19
Size: 2115
Editor: SheenaSmith
Comment: add question
Revision 11 as of 2011-01-28 20:09:51
Size: 2662
Editor: SheenaSmith
Comment: update content - 1/27 changeset 5123
Deletions are marked like this. Additions are marked like this.
Line 43: Line 43:
=== 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.

Porting Note:
 The spin lock functions and type are required and can not be emulated because they are used in the atomic emulation code.

DRAFT

Atomic Operations for 32 and 64 Bit Values

Include File(s): SDL_atomic.h

Introduction

This category contains functions for handling atomic operations in both 32-bit and 64-bit platforms. green

At the very minimum spin locks must be implemented. Without spin locks it is not possible (AFAICT) to emulate the rest of the atomic operations. green

green

/!\ 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.

The list of "safe" functions to use are:

Seriously, here be dragons!

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. green

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

green

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.

Porting Note:

  • The spin lock functions and type are required and can not be emulated because they are used in the atomic emulation code.

Functions


CategoryCategory

None: CategoryAtomic (last edited 2016-06-10 19:46:44 by PhilippWiesemann)

(Page Info.)
Feedback
Please include your contact information if you'd like to receive a reply.
Submit