orc-lang / orc

Orc programming language implementation
https://orc.csres.utexas.edu/
BSD 3-Clause "New" or "Revised" License
41 stars 3 forks source link

synchronized and withLock only allow 1 publication #122

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Procedure to Repeat:
Attempt to synchronize an operation that publishes more than once.

Version and Platform:
SVN r3171 (and after, but I think I am testing at around that build)

Reporter's Comments:
Here is an implementation that avoids the problem. It does require a channel to 
manage the publications (and types would need to be added before it could be 
included in prelude). So both version may be needed so that channels are not 
allocated for every synchronized closure.

def withSemaphore(s, f) =
  val c = Channel()
  repeat(c.get) |
  s.acquire() >> (f() >x> c.put(x) >> stop ; s.release() >> c.close() >> stop) 

Original issue reported on code.google.com by arthur.peters on 23 Apr 2013 at 6:36

arthurp commented 9 years ago

I have fixed versions of this that actually also unlock when the expression is killed. However they require Orco. I don't see any reason to try for a fix before Orco becomes main line.

Deferred until after Orco merge (whenever that is).