Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 20 Apr 2011 10:13:56 +0800
From:      David Xu <davidxu@freebsd.org>
To:        Ryan Stone <rysto32@gmail.com>
Cc:        FreeBSD Current <freebsd-current@freebsd.org>, Ed Maste <emaste@freebsd.org>
Subject:   Re: [PATCH] Call _thr_check_init() from _pthread_once
Message-ID:  <4DAE4164.9080006@freebsd.org>
In-Reply-To: <BANLkTikwT0qOB32DeLMdFkx4vkx6_HAkQg@mail.gmail.com>
References:  <BANLkTikwT0qOB32DeLMdFkx4vkx6_HAkQg@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On 2011/04/20 00:53, Ryan Stone wrote:
> In r179417 the implementation of pthread_once in libthr was changed
> from using a global pthread_mutex_t for synchronization to rolling its
> own synchronization mechanism.  Unfortunately, this introduced a bug.
> Calling _pthread_mutex_lock implicitly ensured that _thr_check_init()
> had been called.  In the current version, there is no such guarantee.
> This means that if your first call into libthr is pthread_once, your
> executable will segfault when it tries to access curthread.  This
> patch resolves the issue for me:
> 
> Index: lib/libthr/thread/thr_once.c
> ===================================================================
> --- lib/libthr/thread/thr_once.c        (revision 220603)
> +++ lib/libthr/thread/thr_once.c        (working copy)
> @@ -64,6 +64,8 @@
>         struct pthread *curthread;
>         int state;
> 
> +       _thr_check_init();
> +
>         for (;;) {
>                 state = once_control->state;
>                 if (state == ONCE_DONE)
> 
> If there are no objections I'll commit this soon.

Have you tested that current code causes segfault ?
anyway, I can not reproduce it on my machne.

Regards,
David Xu



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