[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH] libports: implement lockless management of threads
From: |
Justus Winter |
Subject: |
Re: [PATCH] libports: implement lockless management of threads |
Date: |
Sat, 16 Nov 2013 11:41:03 +0100 |
User-agent: |
alot/0.3.4 |
Quoting Samuel Thibault (2013-11-16 11:16:02)
> > - pthread_spin_lock (&lock);
> > - if (nreqthreads == 1)
> > + __atomic_sub_fetch (&totalthreads, 1, __ATOMIC_RELAXED);
> > + if (__atomic_sub_fetch (&nreqthreads, 1, __ATOMIC_RELAXED) == 0)
> > {
> > /* No other thread is listening for requests, continue. */
> > - pthread_spin_unlock (&lock);
> > + __atomic_add_fetch (&totalthreads, 1, __ATOMIC_RELAXED);
> > + __atomic_add_fetch (&nreqthreads, 1, __ATOMIC_RELAXED);
> > goto startover;
> > }
> > - nreqthreads--;
> > - totalthreads--;
> > - pthread_spin_unlock (&lock);
> > }
>
> Here the totalthreads update should be done after decrementing and
> testing nreqthreads (and thus no reincrement if that gives 0). Otherwise
> master might see totalthreads being 1 although there is actually another
> thread which will happen to realize it'll actually continue. Put
> another way, a thread mustn't decrement totalthreads unless it is
> absolutely sure it will terminate.
Dooh, yes, of course >,<
> With that fixed, Ack.
I just realized that I tested these changes *with* the
libports_stability.patch, so the threads do not actually time out and
so this particular code is never reached. Maybe we should defer this
patch until Richards patch destruction rework is finished and we got
rid of that patch?
Justus
- Re: [PATCH] libports: fix the thread counts in case the thread creation fails, (continued)
- Re: [PATCH] libports: fix the thread counts in case the thread creation fails, Neal H. Walfield, 2013/11/10
- lockless thread management in libports (was: [PATCH] libports: fix the thread counts in case the thread creation fails), Justus Winter, 2013/11/11
- [PATCH] libports: implement lockless management of threads, Justus Winter, 2013/11/11
- Re: [PATCH] libports: implement lockless management of threads, Neal H. Walfield, 2013/11/11
- Re: [PATCH] libports: implement lockless management of threads, Justus Winter, 2013/11/12
- Re: [PATCH] libports: implement lockless management of threads, Samuel Thibault, 2013/11/12
- Re: [PATCH] libports: implement lockless management of threads, Emilio Pozuelo Monfort, 2013/11/13
- Re: [PATCH] libports: implement lockless management of threads, Justus Winter, 2013/11/15
- [PATCH] libports: implement lockless management of threads, Justus Winter, 2013/11/15
- Re: [PATCH] libports: implement lockless management of threads, Samuel Thibault, 2013/11/16
- Re: [PATCH] libports: implement lockless management of threads,
Justus Winter <=
- Re: [PATCH] libports: implement lockless management of threads, Richard Braun, 2013/11/16