bug-hurd
[Top][All Lists]
Advanced

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

Re: [PATCH] libports: implement lockless management of threads


From: Emilio Pozuelo Monfort
Subject: Re: [PATCH] libports: implement lockless management of threads
Date: Wed, 13 Nov 2013 09:21:49 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20131005 Icedove/17.0.9

On 12/11/13 20:13, Samuel Thibault wrote:
> Hello,
> 
> OK, I believe that'll work indeed. What really makes it work is this:
> 
> Justus Winter, le Mon 11 Nov 2013 21:12:34 +0100, a écrit :
>> +      /* Decrement nreqthreads.  */
>> +      unsigned int tc = __atomic_sub_fetch (&thread_counts, 1,
>> +                                        __ATOMIC_RELAXED);
>> +      if (NREQTHREADS (tc) == 0)
> 
> You have atomicity between the decrementation and testing whether the
> resulting value is 0. That's why we were keeping the spinlock along the
> test. The same happens with the test on totalthreads below.
> 
> Now, there is no need for the two counters to be updated coherently,
> they are used for different reasons, and don't actually interfere. Also,
> mixing them into one int reduces the maximum number of threads to 65535,
> which is not so big.

Couldn't 8 byte integers be used here? That would give us the same number of
maximum threads.

Cheers,
Emilio

> So I'd say please move to using two unsigned ints. Yes, it means
> two atomic operations on thread creation/destruction, but that's an
> expensive operation already anyway (and we're not supposed to do that so
> often). Readability of the code is more important than that :)
> 
> Samuel
> 
> 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]