Date: Thu, 24 Feb 2005 15:47:40 +0000 (GMT) From: Robert Watson <rwatson@FreeBSD.org> To: threads@FreeBSD.org, alfred@FreeBSD.org Subject: POSIX semaphores and fork() -- when any process exits, they all lose , access Message-ID: <Pine.NEB.3.96L.1050224154052.18375A-100000@fledge.watson.org>
next in thread | raw e-mail | index | archive | help
I was writing some code to exercise POSIX semaphores this morning, and ran into the following issue: If I create a named POSIX semaphore in a process, then fork(), the semaphore appears to be visible to both the parent and child. However, as soon as the child exits, the semaphore disappears from the parent. This seems likely incorrect, although I don't have a copy of the spec in question so couldn't say for sure. It strikes me that the semaphores should either be shared as of exit, with the child and the parent both having references to it, or they should remain only with the parent, and the childs semaphores should be invalidated/corrupted/something. No doubt POSIX has something to say on the topic. Looking at the kernel code, it looks like the semaphore code is aware of process exit() and exec(), but not fork(), which is probably what leads to this behavior. Since POSIX semaphores in the threaded case involve cooperation between the library and kernel to implement, I suspect getting the semantics right may require a bit of work. Does anyone know what the semantics should be, and/or is interested in making our implementation fit those semantics? Thanks, Robert N M Watson
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.NEB.3.96L.1050224154052.18375A-100000>