Skip to content

Commit

Permalink
ostest/pthread_rwlock: We need to wait for race_cond_thread2
Browse files Browse the repository at this point in the history
to acquire the rdlock first, otherwise it may cause a deadlock.

Signed-off-by: hujun5 <[email protected]>
  • Loading branch information
hujun260 authored and xiaoxiang781216 committed Nov 9, 2024
1 parent eec957a commit e2a2133
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions testing/ostest/pthread_rwlock.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ static FAR void *race_cond_thread1(FAR void *data)
ASSERT(false);
}

sem_wait(rc->sem1);
status = pthread_rwlock_rdlock(rc->rw_lock);
if (status != 0)
{
Expand Down Expand Up @@ -197,6 +198,7 @@ static FAR void *race_cond_thread2(FAR void *data)
ASSERT(false);
}

sem_post(rc->sem1);
if (g_race_cond_thread_pos++ != 3)
{
printf("pthread_rwlock: Thread order unexpected. Expected 3, got %d",
Expand Down

0 comments on commit e2a2133

Please sign in to comment.