Justus Winter, le Fri 15 Nov 2013 20:52:23 +0100, a écrit :
> @@ -224,30 +216,22 @@ ports_manage_port_operations_multithread (struct 
> port_bucket *bucket,
>  
>        if (master)
>       {
> -       pthread_spin_lock (&lock);
> -       if (totalthreads != 1)
> -         {
> -           pthread_spin_unlock (&lock);
> -           goto startover;
> -         }
> +       if (__atomic_load_n (&totalthreads, __ATOMIC_RELAXED) != 1)
> +         goto startover;
>       }
>        else
>       {
> -       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.

With that fixed, Ack.

Samuel

Reply via email to