From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id PAA04898; Fri, 6 Apr 2001 15:21:35 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id PAA04894 for ; Fri, 6 Apr 2001 15:21:34 +0200 (MET DST) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.11.1/8.10.0) with ESMTP id f36DLS506456; Fri, 6 Apr 2001 15:21:28 +0200 (MET DST) Received: (from xleroy@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id PAA04889; Fri, 6 Apr 2001 15:21:29 +0200 (MET DST) Date: Fri, 6 Apr 2001 15:21:29 +0200 From: Xavier Leroy To: Ohad Rodeh Cc: caml-list@inria.fr Subject: Re: [Caml-list] Suspending threads Message-ID: <20010406152129.A4550@pauillac.inria.fr> References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 1.0i In-Reply-To: ; from orodeh@cs.huji.ac.il on Wed, Apr 04, 2001 at 05:15:52PM +0200 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk > I'm trying to suspend a thread and then > have another thread wake it up. However, > I can't find a suspend (nor a dual wake-up) function in > the Threads library. > Any help? Right. The reason there are no "suspend" and "resume" operations on threads is that not all system thread libraries provide it, most notably Posix threads. There are very good reasons not to give these operations to users, because they are extremely error-prone and make little sense from a concurrency point of view: stopping a thread at any time without its consent, e.g. while it is holding a mutex on critical data, can deadlock the whole program. The only legitimate uses for suspend/resume are 1- for low-level services such as garbage collection and debuggers, and 2- to create a thread in the suspended state, finish initialization, then let it run. But Posix decided these uses were not worth supporting :-) As someone else replied, you should use a mutex / boolean reference / condition variable combination so that the thread can voluntarily suspend itself on the condition, and allow other threads to restart it by signalling the condition. The mutex / condition variable / predicate on shared state model inherited from Posix may look heavy and restrictive at first sight, but is actually quite flexible and less error-prone than alternatives. - Xavier Leroy ------------------- To unsubscribe, mail caml-list-request@inria.fr. Archives: http://caml.inria.fr