Re: GLib: atomic integer operations



"Gustavo J. A. M. " Carneiro <gjc inescporto pt> writes:

>   I would like to propose that a set of "atomic integer operations" be
> included in a future glib. Something like this:

Extensive discussion in:

 http://bugzilla.gnome.org/show_bug.cgi?id=63621

> 
>   http://www.mozilla.org/projects/nspr/reference/html/pratom.html#20841
> 
>   These functions are very useful for threaded programs. Advantages:
> 	1. These operations do not require any locking/mutexes, so they are
> super fast!;
> 	2. Thread-safe reference counting of objects without any performance
> penalty;
> 	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.
> /
>     .text
>     .globl _PR_x86_AtomicIncrement
>     .align 4
> _PR_x86_AtomicIncrement:
>     movl 4(%esp), %ecx
>     movl $1, %eax
>     lock
>     xaddl %eax, (%ecx)
>     incl %eax
>     ret
> 
>   For unsupported platforms, the behaviour can be emulated with mutexes, of course.
> 
>   Let me know what you think.



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]