From owner-freebsd-current Thu Aug 6 10:01:42 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id KAA08158 for freebsd-current-outgoing; Thu, 6 Aug 1998 10:01:42 -0700 (PDT) (envelope-from owner-freebsd-current@FreeBSD.ORG) Received: from coleridge.kublai.com (coleridge.kublai.com [207.96.1.116]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id KAA08153 for ; Thu, 6 Aug 1998 10:01:40 -0700 (PDT) (envelope-from shmit@natasya.kublai.com) Received: from natasya.kublai.com (natasya.kublai.com [207.172.25.236]) by coleridge.kublai.com (8.8.8/8.8.8) with ESMTP id NAA10576 for ; Thu, 6 Aug 1998 13:01:23 -0400 (EDT) (envelope-from shmit@natasya.kublai.com) Received: (from shmit@localhost) by natasya.kublai.com (8.8.8/8.8.8) id NAA14193; Thu, 6 Aug 1998 13:01:22 -0400 (EDT) Message-ID: <19980806130122.38511@kublai.com> Date: Thu, 6 Aug 1998 13:01:22 -0400 From: Brian Cully To: current@FreeBSD.ORG Subject: Pthreads woes revisited. Reply-To: shmit@kublai.com Mime-Version: 1.0 Content-Type: multipart/mixed; boundary=FyWQ0h3ruR435lwh X-Mailer: Mutt 0.89i X-Sender: If your mailer pays attention to this, it's broken. X-PGP-Info: finger shmit@kublai.com for my public key. Sender: owner-freebsd-current@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG --FyWQ0h3ruR435lwh Content-Type: text/plain; charset=us-ascii I've put together a small C program that demonstrates the problems I described in my last message. You can find the program attached to this message. Note the location of the `sleep(1)' call, it's important. If it moves outside of the mutex lock/unlock bits, everything functions normally, but if it gets called after the lock, but before the unlock, the first signal is missed. Looks like broken signal handling of some variety. -- Brian Cully ``And when one of our comrades was taken prisoner, blindfolded, hung upside-down, shot, and burned, we thought to ourselves, `These are the best experiences of our lives''' -Pathology (Joe Frank, Somewhere Out There) --FyWQ0h3ruR435lwh Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="ptest2.c" #include #include #include pthread_cond_t wakeup; pthread_mutex_t busy; void * thr_routine(void *arg) { int rc; for (;;) { printf("%d: Waiting for signal.\n", pthread_self); rc = pthread_cond_wait(&wakeup, &busy); if (rc) { fprintf(stderr, "ERROR: couldn't wait for condition: %s.\n", strerror(rc)); return NULL; } printf("%d: Got signal.\n", pthread_self); } return NULL; } int main(int argc, char *argv[]) { int rc; pthread_t thread_id; rc = pthread_cond_init(&wakeup, NULL); if (rc) { fprintf(stderr, "ERROR: couldn't create condition variable: %s.\n", strerror(rc)); return 1; } rc = pthread_mutex_init(&busy, NULL); if (rc) { fprintf(stderr, "ERROR: couldn't create mutex: %s.\n", strerror(rc)); return 1; } rc = pthread_create(&thread_id, NULL, thr_routine, NULL); if (rc) { fprintf(stderr, "ERROR: couldn't create thread: %s.\n", strerror(rc)); return 1; } for (;;) { printf("MASTER: Acquiring lock.\n"); rc = pthread_mutex_lock(&busy); if (rc) { fprintf(stderr, "ERROR: couldn't lock mutex: %s.\n", strerror(rc)); return 1; } sleep(1); printf("MASTER: Releasing lock.\n"); rc = pthread_mutex_unlock(&busy); if (rc) { fprintf(stderr, "ERROR: couldn't unlock mutex: %s.\n", strerror(rc)); return 1; } printf("MASTER: Sending signal.\n"); rc = pthread_cond_signal(&wakeup); if (rc) { fprintf(stderr, "ERROR: couldn't signal thread: %s.\n", strerror(rc)); return 1; } } return 0; } --FyWQ0h3ruR435lwh-- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-current" in the body of the message