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 mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by yquem.inria.fr (Postfix) with ESMTP id 77AA5BC57 for ; Wed, 14 Apr 2010 10:40:53 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AvECAMocxUvRVdrikGdsb2JhbACRQooNCBUBAQEBCQkMBxEDH6wjgXCFcS6ITQEBAwWCEEaCMgSDRQ X-IronPort-AV: E=Sophos;i="4.52,203,1270418400"; d="scan'208";a="60680006" Received: from mail-bw0-f226.google.com ([209.85.218.226]) by mail4-smtp-sop.national.inria.fr with ESMTP; 14 Apr 2010 10:40:52 +0200 Received: by bwz26 with SMTP id 26so7118227bwz.7 for ; Wed, 14 Apr 2010 01:40:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:received:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=ZXEFbSl1pgiOBv7k8F98UVGfJoJj4gBcr4AsvelqUZY=; b=rL+fx7Zl9mKwqT3dg2U4Tjq6f7sm4vkqBpOSz/oH5ik8m4qc4MoSCXarCOMOOZvLmH qF/cvTPIpcFB4NwFMyl93O3AmEIlWNk7rQlpQMklSFaARCgdfjDpvC+3oF0WxWinnlqF ZV2SDVunKkzItnO1NjOk2GIOxW6IsaShqFQ7g= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; b=wvHSGI3Z0rqevoz+eIJ46tSCt78ma9xUVacFT16vzpPVznrQFfYLad0Vx0vHCk9aSj 9OVO8hB3VH+aNfDWfDOSt8UpvZDSqEfZ39FS27wURjHtVcPWe1lbBCVCC1F2DjV3xgpK p15RiMX1oSiVQW8oX7iDCSKDaBAtdd+E9b0Uc= MIME-Version: 1.0 Received: by 10.239.150.81 with HTTP; Wed, 14 Apr 2010 01:40:51 -0700 (PDT) In-Reply-To: References: Date: Wed, 14 Apr 2010 10:40:51 +0200 Received: by 10.103.35.5 with SMTP id n5mr3934903muj.93.1271234451686; Wed, 14 Apr 2010 01:40:51 -0700 (PDT) Message-ID: Subject: Re: [Caml-list] Threads Scheduling From: Philippe Wang To: Gregory Malecha Cc: Caml List Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Spam: no; 0.00; atomically:01 bunzli:01 buenzli:01 scheduler:01 threads:01 threads:01 wrote:01 wrote:01 caml-list:01 functions:01 caml:02 functional:02 groups:02 external:03 external:03 On Tue, Apr 13, 2010 at 11:56 PM, Gregory Malecha wrot= e: > 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 signale= d > 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=FCnzli > wrote: >> >> You may also be interested in this thread [1]. >> >> Daniel >> >> [1] >> http://groups.google.com/group/fa.caml/browse_thread/thread/9606b618dab7= 9fb5 > > > > -- > gregory malecha Hi, Your f function *might* prevent preemption... For instance, if let f () =3D 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, tho= ugh. --=20 Philippe Wang mail@philippewang.info