Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 29 Aug 2008 17:10:43 +0300
From:      Kostik Belousov <kostikbel@gmail.com>
To:        Andriy Gapon <avg@icyb.net.ua>
Cc:        davidxu@freebsd.org, freebsd-threads@freebsd.org
Subject:   Re: mysterious hang in pthread_create
Message-ID:  <20080829141043.GX2038@deviant.kiev.zoral.com.ua>
In-Reply-To: <48B71BA6.5040504@icyb.net.ua>
References:  <48B70A98.5060501@icyb.net.ua> <48B7101E.7060203@icyb.net.ua> <48B71BA6.5040504@icyb.net.ua>

next in thread | previous in thread | raw e-mail | index | archive | help

--YvxfeT9y/1FRS2+9
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Fri, Aug 29, 2008 at 12:41:58AM +0300, Andriy Gapon wrote:
> on 28/08/2008 23:52 Andriy Gapon said the following:
> >So can all this be a result of an exception thrown before threads are=20
> >initialized?
>=20
> This seems to be it.
> I can reproduce the issue with the following small C++ program:
>=20
> /*********************************************/
> #include <pthread.h>
>=20
>=20
> static void * thrfunc(void * arg)
> {
>     return NULL;
> }
>=20
> int main(void)
> {
>     pthread_t thr;
>=20
>     try {
>         throw int(1);
>     }
>     catch (...) {}
>=20
>     pthread_create(&thr, NULL, thrfunc, NULL);
>=20
>     return 0;
> }
> /*********************************************/
>=20
>=20
> $ uname -a
> ... FreeBSD 7.0-STABLE #9: Sun Jul  6 17:13:22 EEST 2008 ... i386
>=20
> --=20
> Andriy Gapon

I am wondering why did you not fixed it youself with all this information.
Anyway, patch below seems to work for me. David may have an opinion on
the change.

diff --git a/lib/libthr/thread/thr_init.c b/lib/libthr/thread/thr_init.c
index f96bba9..785d610 100644
--- a/lib/libthr/thread/thr_init.c
+++ b/lib/libthr/thread/thr_init.c
@@ -355,6 +355,9 @@ _libpthread_init(struct pthread *curthread)
 		if (_thread_event_mask & TD_CREATE)
 			_thr_report_creation(curthread, curthread);
 	}
+
+	if (_thr_isthreaded() =3D=3D 0)
+		_thr_setthreaded(1);
 }
=20
 /*

--YvxfeT9y/1FRS2+9
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (FreeBSD)

iEYEARECAAYFAki4A2IACgkQC3+MBN1Mb4ghwACg48Cq54kIYCRiNPZv4+9fQKsJ
sycAniWJY6CZ2kw79wGzxCWaJfPCvq9L
=Rdug
-----END PGP SIGNATURE-----

--YvxfeT9y/1FRS2+9--



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