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 mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by yquem.inria.fr (Postfix) with ESMTP id CDB2ABC57 for ; Wed, 14 Apr 2010 20:18:40 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AvcCAHqjxUvZSMDdkWdsb2JhbACbVhUBAQEBCQsKBxEDH71rghVGgjIEg0aCeg X-IronPort-AV: E=Sophos;i="4.52,206,1270418400"; d="scan'208";a="57056083" Received: from fmmailgate01.web.de ([217.72.192.221]) by mail1-smtp-roc.national.inria.fr with ESMTP; 14 Apr 2010 20:18:40 +0200 Received: from smtp06.web.de (fmsmtp06.dlan.cinetic.de [172.20.5.172]) by fmmailgate01.web.de (Postfix) with ESMTP id 067EF156CC376; Wed, 14 Apr 2010 20:18:40 +0200 (CEST) Received: from [78.43.204.177] (helo=frosties.localdomain) by smtp06.web.de with asmtp (TLSv1:AES256-SHA:256) (WEB.DE 4.110 #4) id 1O27Ad-0001t7-00; Wed, 14 Apr 2010 20:18:39 +0200 Received: from mrvn by frosties.localdomain with local (Exim 4.71) (envelope-from ) id 1O27Ab-0006it-VN; Wed, 14 Apr 2010 20:18:38 +0200 From: Goswin von Brederlow To: Philippe Wang Cc: Gregory Malecha , Caml List Subject: Re: [Caml-list] Threads Scheduling References: Date: Wed, 14 Apr 2010 20:18:37 +0200 In-Reply-To: (Philippe Wang's message of "Wed, 14 Apr 2010 10:40:51 +0200") Message-ID: <871vehnbia.fsf@frosties.localdomain> User-Agent: Gnus/5.110009 (No Gnus v0.9) XEmacs/21.4.22 (linux, no MULE) MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Sender: goswin-v-b@web.de X-Sender: goswin-v-b@web.de X-Provags-ID: V01U2FsdGVkX19IMNHivhIJduypl4OQ31RKAtQ8iGcSsPwrC3LD VSGSnf1OUc4eFgGxvVNp9Xd21LAUxKnZx4vsRuKc1gRZ1vYIpY Iich9D688= X-Spam: no; 0.00; atomically:01 bunzli:01 buenzli:01 scheduler:01 ocaml:01 mfg:98 threads:01 threads:01 wrote:01 wrote:01 caml-list:01 functions:01 writes:01 caml:02 functional:02 Philippe Wang writes: > On Tue, Apr 13, 2010 at 11:56 PM, Gregory Malecha wrote: >> Hi Jake, >> The documentation for Condition.wait says: >> wait c m atomically unlocks the mutex m and suspends the calling process on >> the condition variable c. The process will restart after the condition >> variable c has been signalled. The mutex m is locked again before wait >> returns. >> I figured that I needed to lock and unlock the mutex in the child threads >> because otherwise it is possible for the condition variable to be signaled >> before the main thread waits, which I thought means that the signal is >> lost. >> Thanks Daniel, I'll take a look at it. >> On Tue, Apr 13, 2010 at 5:04 PM, Daniel Bünzli >> wrote: >>> >>> You may also be interested in this thread [1]. >>> >>> Daniel >>> >>> [1] >>> http://groups.google.com/group/fa.caml/browse_thread/thread/9606b618dab79fb5 >> >> >> >> -- >> gregory malecha > > Hi, > > Your f function *might* prevent preemption... > For instance, if > let f () = while true do () done;; > then it means f does not allocate nor call any external function, and > so it the scheduler is stuck because scheduling is done at allocation > or *some* external functions (which contain "blocking sections", e.g., > I/O operations). > So it is important that when using Thread module, there is, for > scheduling, at some point a call to an allocation or a "blocking" > operation, or Thread.yield. > As most functional code will allocate, this problem is not so frequent, though. Meaning: Ocaml uses cooperative multithreading, not preemptive. MfG Goswin