Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 23 Apr 2000 14:09:40 -0400 (EDT)
From:      Daniel Eischen <eischen@vigrid.com>
To:        Alexander@Leidinger.net, current@FreeBSD.ORG
Subject:   Re: pthread_cond_broadcast() not delivered
Message-ID:  <200004231809.OAA29230@pcnet1.pcnet.com>

next in thread | raw e-mail | index | archive | help
Alexander Leidinger wrote:
> Hi,
> 
> (14) netchild@ttyp2% uname -a
> FreeBSD Magelan.Leidinger.net 5.0-CURRENT FreeBSD 5.0-CURRENT #14: Fri Apr 21 17:28:37 CEST 2000     root@:/big/usr/src/sys/compile/WORK  i386
> 
> I've an application which uses pthread_cond_{wait,broadcast}() and
> the debug output gives me the impression that the broadcast did not get
> delivered anymore.
> 
> I run this program only occasionally, but with 4-current (last year) it
> worked, and I haven't changed anything mutex-/cond-related in it since
> then.
> 
> I've attached a short test-prog (1.7k) which shows the same behavior,
> compile it with "cc -D_THREAD_SAFE -pthread test.c" and run "./a.out".

If you want it to work correctly, you have to make the second thread
release the mutex.  Look at it more closely:

    void *
    second_thread(void *arg)
    {
      /* syncronize */
      fprintf(stderr, "Second: lock.\n");
      pthread_mutex_lock(main_mutex);

      fprintf(stderr, "Second: broadcast.\n");
      pthread_cond_broadcast(main_cond);

      fprintf(stderr, "Second: unlock.\n");
      pthread_mutex_lock(main_mutex);
      ^^^^^^^^^^^^^^^^^^

      fprintf(stderr, "Second: sleep.\n");
      sleep(10);

      fprintf(stderr, "Second: exit.\n");
      pthread_exit(0);
    }

-- 
Dan Eischen


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-current" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200004231809.OAA29230>