Day 87: STM: Atomic power!

autrijus on 2005-04-28T19:25:43

At nothingmuch's request, I changed all IORef and HashTable in Pugs to use TVar, a STM-powered, concurrency-safe, deadlock-free storage. For people who were not following along, here is a presentation and paper about STM as used in GHC.

This means that all our variable access are automatically atomic -- i.e. there can never be corrupted pads when pads are shared among multiple async blocks. By nothingmuch and my benchmarking, there is no visible performance loss.

In other news, I eliminated the troublesome mutual module recursion, to pave a way for a new EvalT monad transformer that can expose atomic {} to Perl 6 level. The idea is that this should work:

    my ($x, $y) = (1, 2);
    async { atomic { $x = $y * 10; $y = $x * 10 } };
    async { atomic { $x = $y * 10; $y = $x * 10 } };
    async { atomic { $x = $y * 10; $y = $x * 10 } };
    atomic { $x = $y * 10; $y = $x * 10 };
    say "$x, $y"; # always "20000000, 200000000"
But this should throw a catchable exception:
    # die "Can't perform IO inside atomic {} block"
    atomic { say "Hello, World!" };
I'm having some problems in modeling the neccessary MonadCont continuation semantic, so atomic is not exposed right now. However, as a happy side effect, the elimination of mutual recursion has improved performance by another 15% or so. Yay for a fast Pugs!

There are many other notable changes today as well:

  • Stevan committed a working Pod::Stream::Parser to ext/, in preparation for Pugs to be self-documenting.
  • Speaking about documentation, theorbtwo started investigating adding Haddock annotations to Pugs. I have used Haddock for my first Haskell project, OpenAFP, and it is indeed very pretty and useful.
  • For OpenAFP, I added a VOpaque value type, to encapsuate any other types into an opaque reference. The upshot is that we should be able to manipulate arbitary Haskell types (and by extension, C types) as Pugs objects soon.
  • nothingmuch fixed eval_is and eval_ok, then proceeds to implement .wrap. Juerd, I and nothingmuch all agreed that the current semantics in S06 (based on Hook::LexWrap) is very awkward, and conflicts with how .assuming behaves; we worked out a much more perlish semantics, and nothingmuch proceeded to implement it.
  • machack666 is working on supporting block closure traits like FIRST; his work may also provide a more generic trait system for other structures to use.
  • andras checked in Memory Game v0.2, this time with tooltips on each boxes and a turns counter.
  • iblech continues to update loose ends everywhere, including the mandelbrot tests, BEGIN {...} block tests, and more.
  • bsb, nothingmuch and I moved readline probing to Makefile.PL, so the interactive shell should be usable for people who needs the -package readline flag.
  • bsb tested and fixed pick's behaviour on one junctions: one(1).pick should return 1, but one(1,1).pick should be undef.
  • gaal made the YAML harness sort its input, so our tests are always run in the same order, regardless of the underlying filesystem. rootmj also committed a small message fix in run-smoke.pl
  • Stevan and Limbic_Region added some last/next tests.
  • revdiablo, our new committer, added various tests on recursive function calls and subroutine references.
  • mugwump added tests for a function returning its inner function, ensuring that the inner pad is being preserved.

See you tomorrow!


Um, can you fix the URLs?

hans on 2005-05-01T19:28:46

Hi,

The two URLs about STM in the Thursday April 28 entry are identical, both referring to the presentation. Could you post the URL to the paper?

Thanks

Hans

Re:Um, can you fix the URLs?

autrijus on 2005-05-03T13:17:33

Why, sure, fixed, thanks!