From: Rich Neswold <rich.neswold@gmail.com>
To: Goswin von Brederlow <goswin-v-b@web.de>
Cc: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Smart ways to implement worker threads
Date: Fri, 16 Jul 2010 11:18:26 -0500 [thread overview]
Message-ID: <AANLkTinJbOtdS-BT5Cma9hwzsPDEOuMmUCl5FPvVfia-@mail.gmail.com> (raw)
In-Reply-To: <87630fbmvb.fsf@frosties.localdomain>
[-- Attachment #1: Type: text/plain, Size: 1563 bytes --]
On Fri, Jul 16, 2010 at 8:02 AM, Goswin von Brederlow <goswin-v-b@web.de>wrote:
> Yeah. But then why not build it around the simple Mutex and Condition
> modules instead of Event? At first glance the blocking aspect of Events
> seem to be more of a hindrance than help.
>
The problem with Mutex and Condition is all the management that goes with
them. You must make sure your unlocks match your locks -- even in the
presence of exceptions. None of this bookkeeping is required from the
programmer when using Event.
The bigger win for Events, though, is that they're composable.
Let's say you decide to have two queues to communicate with two workers.
With the mutex/queue scenario, you'd have to resort to polling each queue --
locking and unlocking each mutex in turn (or decide that a single mutex
protects both queues ... but this approach doesn't scale well.)
With events, you pass a list of events to 'Event.choose' and the process
will be awakened when one of the events returns a value. No need to widen
the protection of mutexes; adding more events to the list is enough.
Granted, if you mix and match event types (sends and receives, for instance)
you may have to use 'Event.wrap' to make sure they return a compatible type.
Event may not be the best solution for your problem, or it may even lie
outside your comfort zone. Hopefully this discussion has, at the very least,
made some OCaml users take another look at the Event module.
--
Rich
Google Reader: https://www.google.com/reader/shared/rich.neswold
Jabber ID: rich@neswold.homeunix.net
[-- Attachment #2: Type: text/html, Size: 2091 bytes --]
next prev parent reply other threads:[~2010-07-16 16:18 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-07-14 16:09 Goswin von Brederlow
2010-07-15 15:58 ` [Caml-list] " Rich Neswold
2010-07-15 16:19 ` David McClain
2010-07-15 17:16 ` Ashish Agarwal
2010-07-15 18:24 ` Goswin von Brederlow
2010-07-15 18:37 ` David McClain
2010-07-15 18:40 ` David McClain
2010-07-15 19:56 ` Rich Neswold
2010-07-16 4:02 ` Goswin von Brederlow
2010-07-16 4:23 ` Rich Neswold
2010-07-16 13:02 ` Goswin von Brederlow
2010-07-16 14:40 ` Dawid Toton
2010-07-16 16:18 ` Rich Neswold [this message]
2010-07-17 17:53 ` [Caml-list] " Eray Ozkural
2010-07-20 4:54 ` Satoshi Ogasawara
2010-07-17 18:34 ` Eray Ozkural
2010-07-17 19:35 ` Goswin von Brederlow
2010-07-17 22:00 ` Eray Ozkural
2010-07-15 16:32 ` Romain Beauxis
2010-07-15 17:46 ` Goswin von Brederlow
2010-07-15 18:44 ` Romain Beauxis
2010-07-16 3:52 ` Goswin von Brederlow
2010-07-16 4:19 ` Romain Beauxis
2010-07-16 13:05 ` Goswin von Brederlow
2010-07-16 13:20 ` Romain Beauxis
2010-07-17 9:07 ` Goswin von Brederlow
2010-07-17 13:51 ` Romain Beauxis
2010-07-17 14:08 ` Goswin von Brederlow
2010-07-17 9:52 ` Goswin von Brederlow
2010-07-17 14:20 ` Romain Beauxis
2010-07-17 15:52 ` Goswin von Brederlow
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=AANLkTinJbOtdS-BT5Cma9hwzsPDEOuMmUCl5FPvVfia-@mail.gmail.com \
--to=rich.neswold@gmail.com \
--cc=caml-list@yquem.inria.fr \
--cc=goswin-v-b@web.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox