archives

RAII and Async Stackless Fibers

I like RAII for exception safe programming, and as a general model for resource management. In another thread it was mentioned that this does not work well with an asynchronous stackless fibre model (where stackless might mean cactus stacks). As I like the fibre model for managing concurrency as well, because you don't need to have threads waiting on high latency services, I wanted to continue that discussion, focusing on: is RAII really a problem with these kind of fibres? What is the core problem? How could a new language combine these features in a way that avoids the problem (if the problem is a significant one)?

I don't really see what the problem is, as in simple terms RAII is attaching a resource (be it memory, file-handle, or any other) to a handle that is placed on a stack. The resource is allocated when the handle is created, and freed when the handle is destroyed. The handle is uncopyable, so it can only be assigned using move-semantics. Naively this would seem to work fine with cactus stacks.

Don't use "Yield" for co-routines; instead use "Postpone"

A pattern followed “↑” and a type can be used to match the pattern with something which has been extended from the type. For example,

 
PostponedFringe.[aTree:Tree]:FutureList◅String▻  ≡ 
   aTree � 
       aLeaf↑Leaf ⦂ [aLeaf.getString[ ]] ⍌
       aFork↑Fork ⦂ [⩛Fringe.[aFork.getLeft[ ]],  ⩛Postpone Fringe.[aFork.getRight[ ]]]

For example, ["The", "boy"]▮ is equivalent to the following:
PostponedFringe.[Fork.[Leaf.["The"], Leaf.["boy"]]]▮

The procedure Fringe can be used to define SameFringe? that determines if two trees have the same fringe [Hewitt 1972]:

   SameFringe?.[aTree:Tree, anotherTree:Tree]:Boolean ≡  //  test if two trees have the same fringe
               PostponedFringe.[aTree] = PostponedFringe.[anotherTree]▮

For example, [False, True]▮ is equivalent to the following:

Let aList ← PostponedFringe.[Fork.[Leaf.["The"], Leaf.["boy"]]]。    // aList = ["The", "boy"]
  [SameFringe?.[aList, ["The", "girl"],              // False
   SameFringe?.[aList, ["The", "boy"]]]▮           // True

Note that Leaf can be defined as an extension of Tree:

Actor Leaf.[aString:String] extension Tree using
        getString[ ]:String → aString▮

and Fork can be defined as an extension of Tree:

Actor Fork.[aLeft:Tree, aRight:Tree] extension Tree using
        getLeft[ ]:Tree → aLeft,
        getRight[ ]:Tree → aRight▮

Edited for clarity.