public inbox for glibc-bugs@sourceware.org help / color / mirror / Atom feed
From: "jsm28 at gcc dot gnu.org" <sourceware-bugzilla@sourceware.org> To: glibc-bugs@sources.redhat.com Subject: [Bug nptl/14532] New: Generic sem_post race Date: Thu, 30 Aug 2012 19:14:00 -0000 [thread overview] Message-ID: <bug-14532-131@http.sourceware.org/bugzilla/> (raw) http://sourceware.org/bugzilla/show_bug.cgi?id=14532 Bug #: 14532 Summary: Generic sem_post race Product: glibc Version: 2.16 Status: NEW Severity: normal Priority: P2 Component: nptl AssignedTo: unassigned@sourceware.org ReportedBy: jsm28@gcc.gnu.org CC: drepper.fsp@gmail.com Classification: Unclassified The generic Linux version of sem_post (nptl/sysdeps/unix/sysv/linux/sem_post.c) uses atomic_compare_and_exchange_bool_acq to increment the semaphore. This is an unlock operation and should actually be using a release barrier. The following test fails on some MIPS systems (MIPS uses the generic version of sem_post where various architectures use their own .S versions). Testing a patch. #include <pthread.h> #include <semaphore.h> #include <stdio.h> #define NTHREADS 10 #define NITER 100000 sem_t sem; int c; volatile int thread_fail; static void * tf (void *arg) { for (int i = 0; i < NITER; i++) { if (sem_wait (&sem) != 0) { perror ("sem_wait"); thread_fail = 1; } ++c; if (sem_post (&sem) != 0) { perror ("sem_post"); thread_fail = 1; } } return NULL; } int main (void) { if (sem_init (&sem, 0, 0) != 0) { perror ("sem_init"); return 1; } pthread_t th[NTHREADS]; for (int i = 0; i < NTHREADS; i++) { if (pthread_create (&th[i], NULL, tf, NULL) != 0) { puts ("pthread_create failed"); return 1; } } if (sem_post (&sem) != 0) { perror ("sem_post"); return 1; } for (int i = 0; i < NTHREADS; i++) if (pthread_join (th[i], NULL) != 0) { puts ("pthread_join failed"); return 1; } if (c != NTHREADS * NITER) { printf ("c = %d, should be %d\n", c, NTHREADS * NITER); return 1; } return thread_fail; } -- Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- You are on the CC list for the bug.
next reply other threads:[~2012-08-30 19:14 UTC|newest] Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top 2012-08-30 19:14 jsm28 at gcc dot gnu.org [this message] 2012-08-31 19:52 ` [Bug nptl/14532] " jsm28 at gcc dot gnu.org 2014-06-25 6:49 ` fweimer at redhat dot com
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-14532-131@http.sourceware.org/bugzilla/ \ --to=sourceware-bugzilla@sourceware.org \ --cc=glibc-bugs@sources.redhat.com \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).