More Delay/Semaphore "fun"

Craig Latta craig at netjam.org
Wed Oct 10 01:53:13 UTC 2007


Hi--

      Igor:    "Then the only way is to make it to handle all by VM."

      Andreas: "Maybe not quite. Check out
                http://bugs.squeak.org/view.php?id=6588 to see if this
                addresses your problem. It appears to work remarkably
                well for me."

      Igor:    "A bit hacky approach, don't you think?"

      Andreas: "Without any doubt. But I don't see a quick solution to
                the problem that isn't a bit of a hack. It's not clear
                what a VM-driven solution looks like either btw."

      I haven't yet thought of a solution that isn't a hack, either. :) 
  But here's a possible VM-assisted solution:

***

Semaphore>>critical: block
      "If I have an excess signal, evaluate block. If I don't, wait for a
       signal first."

      | marker waited |

      "Push a marker into an indexed slot of this context."
      marker := #aboutToWaitForCriticalSection.

      waited := false.

      ^[
           self wait.
           block value
      ]
           ensure: [
                "Interpreter>>transferTo: checks to see if it's
                 transferring to a process whose suspended context has
                 the above marker in it, at the expected slot. If so, it
                 sets waited to true, since that process has, in fact,
                 successfully waited."

                waited ifTrue: [self signal]]

***

      Although still a hack, it seems simple and sufficiently cheap. 
Good for a laugh, anyway. :)


-C

--
Craig Latta
improvisational musical informaticist
www.netjam.org
Smalltalkers do: [:it | All with: Class, (And love: it)]




More information about the Squeak-dev mailing list