Re: pthread library related

2016-05-31 Thread Martin Husemann
On Tue, May 31, 2016 at 04:49:00AM +0200, Steffen Nurpmeso wrote: > Joerg Sonnenberger wrote: > |On Mon, May 30, 2016 at 02:19:26PM -0700, Charles Cui wrote: > |> good to know atomic_inc_uint_nv is implemented using cas. > | > |No, atomic_inc is *not* necessarily implemented using CAS. There a

Re: pthread library related

2016-05-31 Thread Steffen Nurpmeso
Joerg Sonnenberger wrote: |On Mon, May 30, 2016 at 02:19:26PM -0700, Charles Cui wrote: |> good to know atomic_inc_uint_nv is implemented using cas. | |No, atomic_inc is *not* necessarily implemented using CAS. There are a What a pity. |couple of different ways to do it ranging from implici

Re: pthread library related

2016-05-31 Thread Joerg Sonnenberger
On Mon, May 30, 2016 at 02:19:26PM -0700, Charles Cui wrote: > good to know atomic_inc_uint_nv is implemented using cas. No, atomic_inc is *not* necessarily implemented using CAS. There are a couple of different ways to do it ranging from implicit serialisation on UP-only systems over CAS/LL-SC lo

Re: pthread library related

2016-05-31 Thread Charles Cui
good to know atomic_inc_uint_nv is implemented using cas. I will update the patch and send you guys later (being careful about the format) Thanks Charles 2016-05-30 13:46 GMT-07:00 Christos Zoulas : > On May 30, 1:43pm, charles.cui1...@gmail.com (Charles Cui) wrote: > -- Subject: Re: pthread li

Re: pthread library related

2016-05-31 Thread Charles Cui
I am not familiar with _nv() (are there examples in the netbsd code base? I searched _nv() in nxr, but did not found anything meaningful.), but if you want to use atomic operations, one possible way is compare-and-swap (CAS). it has stronger guarantee than atomic inc or atomic dec, but also larger

Re: pthread library related

2016-05-31 Thread Charles Cui
No, using atomic_inc / atomic_dec for p_nsem is wrong! Let's think about the multithreading case. Let's use 2 threads A and B in the same process as an example. Assume p_nsem is not reaching the limit, but only one slot is left. A and B will each read the p_nsem separately. There will be probabi