Skip to content

Commit

Permalink
Fix aliasing problem in tst-sem11.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ulrich Drepper committed Oct 30, 2009
1 parent 3005703 commit 9c04f7c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
2 changes: 2 additions & 0 deletions nptl/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
2009-10-30 Ulrich Drepper <drepper@redhat.com>

* tst-sem11.c (main): Rewrite to avoid aliasing problems.

[BZ #3270]
* allocatestack.c (__nptl_setxid): Perform the operation in multiple
steps to avoid races with creation and terminations.
Expand Down
18 changes: 10 additions & 8 deletions nptl/tst-sem11.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,25 @@ main (void)
{
int tries = 5;
pthread_t th;
sem_t s;
union
{
sem_t s;
struct new_sem ns;
} u;
again:
if (sem_init (&s, 0, 0) != 0)
if (sem_init (&u.s, 0, 0) != 0)
{
puts ("sem_init failed");
return 1;
}

struct new_sem *is = (struct new_sem *) &s;

if (is->nwaiters != 0)
if (u.ns.nwaiters != 0)
{
puts ("nwaiters not initialized");
return 1;
}

if (pthread_create (&th, NULL, tf, &s) != 0)
if (pthread_create (&th, NULL, tf, &u.s) != 0)
{
puts ("pthread_create failed");
return 1;
Expand All @@ -62,11 +64,11 @@ main (void)
if (r != PTHREAD_CANCELED && --tries > 0)
{
/* Maybe we get the scheduling right the next time. */
sem_destroy (&s);
sem_destroy (&u.s);
goto again;
}

if (is->nwaiters != 0)
if (u.ns.nwaiters != 0)
{
puts ("nwaiters not reset");
return 1;
Expand Down

0 comments on commit 9c04f7c

Please sign in to comment.