From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by yquem.inria.fr (Postfix) with ESMTP id 593ACBB9C for ; Tue, 22 Nov 2005 18:32:57 +0100 (CET) Received: from kvi.nl (KVIS12.KVI.nl [129.125.27.62]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id jAMHWuTQ029307 (version=TLSv1/SSLv3 cipher=DES-CBC3-SHA bits=168 verify=NO) for ; Tue, 22 Nov 2005 18:32:57 +0100 Received: from KVIS10.KVI.nl ([129.125.27.60] verified) by kvi.nl (CommuniGate Pro SMTP 4.3.2) with ESMTP id 3200709 for caml-list@yquem.inria.fr; Tue, 22 Nov 2005 18:32:56 +0100 Received: from kvis12.kvi.nl by KVIS10.KVI.nl (AvMailGate-2.0.3-25) id 13278-147BF9FB; Tue, 22 Nov 2005 18:32:56 +0100 Received: by kvis12.kvi.nl (Postfix, from userid 0) id 28A66C40BB; Tue, 22 Nov 2005 18:32:56 +0100 (CET) Received: from [129.125.15.152] (HELO kvip88) by kvi.nl (CommuniGate Pro SMTP 4.3.2) with ESMTPS id 3200708 for caml-list@yquem.inria.fr; Tue, 22 Nov 2005 18:32:55 +0100 From: "Alexander S. Usov" Organization: KVI To: caml-list@yquem.inria.fr Subject: Re: [Caml-list] Threads & Fork Date: Tue, 22 Nov 2005 18:32:55 +0100 User-Agent: KMail/1.9 References: <1132673981.13170.17.camel@starlight> <87wtj07kv8.fsf@mid.deneb.enyo.de> <20051122155002.GB16451@first.in-berlin.de> In-Reply-To: <20051122155002.GB16451@first.in-berlin.de> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200511221832.55487.A.S.Usov@kvi.nl> X-AntiVirus: checked by AntiVir MailGate (version: 2.0.3-25; AVE: 6.32.0.58; VDF: 6.32.0.210; host: kvi.nl) X-Miltered: at nez-perce with ID 43835648.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 threads:01 oliver:01 bandel:01 threads:01 ocaml:01 run-time:01 posix:01 posix:01 api:01 unix-module:01 threading:01 clashing:01 mutexes:01 invariants:01 X-Spam-Checker-Version: SpamAssassin 3.0.3 (2005-04-27) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.1 required=5.0 tests=FORGED_RCVD_HELO autolearn=disabled version=3.0.3 On Tuesday 22 November 2005 16:50, Oliver Bandel wrote: > On Tue, Nov 22, 2005 at 04:39:07PM +0100, Florian Weimer wrote: > > * Jonathan Bryant: > > > I'm confused as to why the attached code hangs. My understanding of > > > Unix.fork () is that it completely clones the current process, which in > > > my understanding, clones the processes's threads as well. Apparently, > > > though, that is not the case, because I can't join the thread in both > > > the parent and the child. > > > > I can't speak for the OCaml run-time, but POSIX fork only duplicates > > the current thread, so the new process is essentially single-threaded. > > I doubt that this is true. > Unix-fork() copies a complete process. > If the original has threads, the copy also have. > I don't think that POSIX handles this different to old Unix API. > > Unix-module should do the same as the C-call of fork(2). > > Threads are running inside a process, like any other > function. So all should be copied completely. > > But using POSIX-threads and Unix-API can yield to many problems, > for example POSIX threading signals and Unix-signals are clashing > together and the behaviour can be undefined... [Option End]A process shall be created with a single thread. If a multi-threaded process calls fork(), the new process shall contain a replica of the calling thread and its entire address space, possibly including the states of mutexes and other resources. Consequently, to avoid errors, the child process may only execute async-signal-safe operations until such time as one of the exec functions is called. [THR] [Option Start] Fork handlers may be established by means of the pthread_atfork() function in order to maintain application invariants across fork() calls. [Option End] (c) SUS v3 -- Best regards, Alexander.