caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jonathan Bryant <jtbryant@valdosta.edu>
To: caml-list@yquem.inria.fr
Subject: Fwd: [Caml-list] CamlP4 and Threads
Date: Sat, 27 Jan 2007 19:15:18 -0500	[thread overview]
Message-ID: <321BC7B3-8A0F-4FF9-B445-BEC5930F9BCE@valdosta.edu> (raw)
In-Reply-To: <60A08B0C-3C02-47D6-8987-00ECF210C982@valdosta.edu>

Forgot to cc this to the list...

Begin forwarded message:

> From: Jonathan Bryant <jtbryant@valdosta.edu>
> Date: January 27, 2007 6:44:32 PM EST
> To: Jonathan Roewen <jonathan.roewen@gmail.com>
> Subject: Re: [Caml-list] CamlP4 and Threads
>
>
> On Jan 27, 2007, at 6:41 PM, Jonathan Roewen wrote:
>
>> 1) have you actually tested the code? you don't pass an initial value
>> to Thread.create, so it won't ever start.
>
> That was a typo.  I meant:
>
> let _ = Thread.create (fun c -> ...) c in
>
>> 2) to avoid the space leak, wouldn't removing the let binding fix
>> this? e.g. Event.sync (Event.send c (f x y z)). Since it's
>> automatically generated code, I don't see the problem with that.
>
> No, that doesn't fix the problem.  The problem is that the thread  
> doesn't stop executing until the event is synchronized upon, and if  
> the return value is ignored it is never synchronized on and the  
> thread waits forever.
>
>> 3) the actual camlp4 thing? I don't know :-) I have toyed with camlp4
>> though, and I found it simplest when introducing new keywords in
>> Pcaml.expr. camlp4 certainly doesn't seem to be for the faint of  
>> heart
>
> I'm trying to avoid keywords if at all possible.
>
>> ;-)
>>
>> Have you tried printing out the various rules, etc? There are some
>> cool functions to do that, and I found it helps to understand all the
>> various precendences, and what the various rules are.
>>
>> Jonathan
>>
>> On 1/28/07, Jonathan Bryant <jtbryant@valdosta.edu> wrote:
>>> I'm think I'm finally understanding CamlP4 and I'm trying to make a
>>> small syntax extension using it, but I can't find the rule I need to
>>> extend.  I want to turn this:
>>>
>>> let f x y x = ....
>>> let x = |f| x y z
>>>
>>> into this:
>>>
>>> let f x y z = ...
>>> let x =
>>>   let c = Event.new_channel () in
>>>   let _ = Thread.create (fun c -> let x = f x y z in Event.sync
>>> (Event.send c x)) in
>>>   Event.receive c
>>>
>>> but, like I said, I can't seem to find the rule I need to extend.  I
>>> can do it for an arbitrary expression:
>>>
>>> let x = |3 + 5|
>>>
>>> to
>>>
>>> let x =
>>>   let c = Event.new_channel () in
>>>   let _ = Thread.create (fun c -> let x = 3 + 5 in Event.sync
>>> (Event.send c x)) in
>>>   Event.receive c
>>>
>>> just not function application.
>>>
>>> I've tried extending Pcaml.expr's "apply" but that doesn't seem to
>>> work, and I can't see any other place to do it.
>>>
>>> Also, it seems that the implementation of the Event module has an
>>> error: the above code causes a space leak if x is not synchronized
>>> upon.  In CML (the basis for the Event module), threads are GCed  
>>> when
>>> they go out of scope, so this is not a problem.  As a matter of  
>>> fact,
>>> it is cited as the way to go about things.  But since OCaml doesn't
>>> GC threads, this is a problem.  Does anyone know of a workaround for
>>> this?  And/or should it be submitted as a bug report?
>>>
>>> --Jonathan Bryant
>>>
>>> _______________________________________________
>>> Caml-list mailing list. Subscription management:
>>> http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
>>> Archives: http://caml.inria.fr
>>> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
>>> Bug reports: http://caml.inria.fr/bin/caml-bugs
>>>
>


           reply	other threads:[~2007-01-28  0:16 UTC|newest]

Thread overview: expand[flat|nested]  mbox.gz  Atom feed
 [parent not found: <60A08B0C-3C02-47D6-8987-00ECF210C982@valdosta.edu>]

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=321BC7B3-8A0F-4FF9-B445-BEC5930F9BCE@valdosta.edu \
    --to=jtbryant@valdosta.edu \
    --cc=caml-list@yquem.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).