hang when using pthread and fork in 1.5.23-1 and snapshot 20070118.

Al Slater al.slater@scluk.com
Wed Jan 31 15:41:00 GMT 2007


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Peter Rehley wrote:
> Hello,
> 
> One of the applications I've been working with has hanging issues.  It
> will sometimes work properly, and sometimes it will hang and never
> continue through the rest of the program.

I have not done any pthread programming under cygwin, but I have done a
fair bit under Solaris.

In my experience threads and fork are not good bedfellows, you need to
excercise care in order to avoid deadlock.

- From the solaris fork() man page :

  fork() Safety
     If a multithreaded application calls fork() or fork1(),  and
     the  child  does  more  than  simply call one of the exec(2)
     functions, there is a possibility of deadlock  occurring  in
     the  child. The application should use pthread_atfork(3C) to
     ensure safety with respect to this deadlock. Should there be
     any outstanding mutexes throughout the process, the applica-
     tion should call pthread_atfork() to wait  for  and  acquire
     those  mutexes prior to calling fork() or fork1(). See  "MT-
     Level of Libraries" on the attributes(5) manual page.

Using stdio in the child after fork in a multithreaded apps has caused
me pain on many occasions, also std::string in c++.

A recommended way to deal with this that I have seen on the web is to
spawn a process before any threads to handle the forks, and use pipes to
communicate between the threads and the forking process.

- --
Al Slater

Technical Director
Stanton Consultancy Ltd

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFFwLEPz4fTOFL/EDYRAmIEAJ43G/LidV+qDdG9Yr2CdxJ2B2L/lwCfTHfI
D1/DfKCQpuda8Kw2OTii51k=
=OaGK
-----END PGP SIGNATURE-----


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/



More information about the Cygwin mailing list