NoSuchProcess / phantomuserland

Automatically exported from code.google.com/p/phantomuserland
GNU Lesser General Public License v3.0
0 stars 0 forks source link

atomic refcount #3

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
refcount is not proteced with spinlock and is not atomic

redo so that all negative values are forbidden?

refc++; if( refc < 0 ) refc--;

and

refc--; if( refc < 0 ) refc++;

these forms can work without locks at all - is it?

check near zero behaviour?

Original issue reported on code.google.com by dmitry.zavalishin@gmail.com on 13 Aug 2009 at 9:27

GoogleCodeExporter commented 8 years ago
As to my understanding it is generally wrong to not using atomic operation here.

We may feel OK with preemption, but the real problem is write barrier:
generally arithmetic done in registers but the compiler may optimize load/store
operation on time line.

So we need a hint to compiler (spinlock does it), or use assembler, or modern 
http://gcc.gnu.org/onlinedocs/gcc-4.4.2/gcc/Atomic-Builtins.html#Atomic-Builtins

Original comment by leonid.p...@gmail.com on 11 Nov 2009 at 12:34

GoogleCodeExporter commented 8 years ago

Original comment by dmitry.zavalishin@gmail.com on 3 Oct 2010 at 9:10

GoogleCodeExporter commented 8 years ago
tests too!

Original comment by dmitry.zavalishin@gmail.com on 3 Mar 2011 at 9:41

GoogleCodeExporter commented 8 years ago
btw, concurrent inc/dec tests show no problems. Bad tests? :)

Original comment by dmitry.zavalishin@gmail.com on 11 Mar 2011 at 11:23