caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Quetzalcoatl Bradley <qbradley@blackfen.com>
To: Caml Users Mailing List <caml-list@inria.fr>
Subject: Re: [Caml-list] Resource acquisition is initialization
Date: Thu, 12 Dec 2002 14:17:42 -0800	[thread overview]
Message-ID: <88762044-0E1F-11D7-BC2C-003065AB3928@blackfen.com> (raw)
In-Reply-To: <20021212141506.A24877@pauillac.inria.fr>


On Thursday, December 12, 2002, at 05:15  AM, Xavier Leroy wrote:
> For a mutex:
>
> let synchronize mut action =
>   try
>     Mutex.lock mut;
>     let res = action () in
>     Mutex.unlock mut;
>     res
>   with x ->
>     Mutex.unlock mut;
>     raise x
>
> You get the idea.

For fun I try to use campl4 to add synchronize directive.

usage:   synchronize "expression that evaluates to Mutex.t" in 
"expression"
The value is result of "expression".

  Example:

let lock = Mutex.create ();;
let counter = ref 0;;
let next_sym prefix =
   synchronize lock in
     let current = !counter in
       counter := current + 1;
       prefix ^ (string_of_int current)
;;

synchronize.ml file:

open Pcaml;;

EXTEND
  expr: LEVEL "expr1"
   [[ "synchronize"; e1 = expr; "in"; e2 = expr ->
    <:expr<
     let __synchronize_lock = $e1$ in
     do {
      Mutex.lock __synchronize_lock;
     try
      let __synchronize_result = $e2$ in
      do { Mutex.unlock __synchronize_lock; __synchronize_result }
     with z ->
      do { Mutex.unlock __synchronize_lock; raise z }
     }
    >>
   ]];
END;;
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


  parent reply	other threads:[~2002-12-13 11:27 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-12-11 19:19 Blair Zajac
2002-12-11 19:55 ` Brian Hurt
2002-12-12  0:27   ` Chet Murthy
2002-12-12  7:56   ` Alessandro Baretta
2002-12-12 16:39     ` Brian Hurt
2002-12-13  9:22   ` Mike Potanin
2002-12-13 17:05     ` David Brown
2002-12-12 13:15 ` Xavier Leroy
2002-12-12 14:05   ` Dmitry Bely
2002-12-12 14:16     ` Xavier Leroy
2002-12-12 22:17   ` Quetzalcoatl Bradley [this message]
2002-12-12 23:59   ` Blair Zajac

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=88762044-0E1F-11D7-BC2C-003065AB3928@blackfen.com \
    --to=qbradley@blackfen.com \
    --cc=caml-list@inria.fr \
    /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;
as well as URLs for NNTP newsgroup(s).