GLib: atomic integer operations
- From: "Gustavo J. A. M. " Carneiro <gjc inescporto pt>
- To: GTK Development list <gtk-devel-list gnome org>
- Subject: GLib: atomic integer operations
- Date: 30 Dec 2002 15:29:51 +0000
I would like to propose that a set of "atomic integer operations" be
included in a future glib. Something like this:
These functions are very useful for threaded programs. Advantages:
1. These operations do not require any locking/mutexes, so they are
2. Thread-safe reference counting of objects without any performance
3. They're very simple to implement; It takes only a few asm
instructions. Example (from NSPR):
/ PRInt32 _PR_x86_AtomicIncrement(PRInt32 *val)
/ Atomically increment the integer pointed to by 'val' and return
/ the result of the increment.
movl 4(%esp), %ecx
movl $1, %eax
xaddl %eax, (%ecx)
For unsupported platforms, the behaviour can be emulated with mutexes, of course.
Let me know what you think.
Gustavo João Alves Marques Carneiro
<gjc inescporto pt> <gustavo users sourceforge net>
] [Thread Prev