Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Date: Thu, 16 Dec 2021 23:25:35 +0800 (CST)
From: zuotina <>
Subject: [pthread] pthread_barrier_wait  invalid case

Hi everrone

I encountered a panic problem when using timer_create recently.
Although the probability is small, it still happened.
Finaly I found there is a problem in the code of phtread_barrier_wait, 
and review code found that there may be problems in the following place, 
81  a_store(&b->_b_lock, 0);
82  if (b->_b_waiters) __wake(&b->_b_lock, 1, 1);
If scheduling occurs between lines 81 and 82, it will be not good.
So I did an experiment and modified the source code of pthread_barrier_wait to verify my guess
81  a_store(&b->_b_lock, 0);
                 /* If it is scheduled out here, when another thread executes pthread_barrier_wait again, 
                    it can go through the entire function happily, that is, it will not be blocked */
      syscall(yiled); // new add for test
               // When the dispatch comes back, this b has been released
82  if (b->_b_waiters) __wake(&b->_b_lock, 1, 1);
Here is an example of timer_create (src/time/timer_create.c)
There are two threads A and B call pthread_barrier_wait. 
The call is as follows
A thread: (timer_create // parent thread)
      // new add for test---begin
       while(b->_b_inst == NULL) {
     // new add for test---end
B thread: (start // child thread)
      //  Ensure that this function is advanced to the if (!inst) {} branch of barrier_wait

In short, the reason for panic is that pthread_barrier_wait is not blocked as expected;
I hope you help to confirm whether there is a problem with the implementation 
of pthread_barrier_wait or am I wrong?

Looking forward to your reply. Thank you. 
Content of type "text/html" skipped

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.