[MLton-user] Raw conversion of 32 bits into Real32.t

Henry Cejtin henry.cejtin at sbcglobal.net
Mon Jan 22 16:04:31 PST 2007


The  problem  of the thread-safe aspect of allocation outside a function call
has   already   been   solved.    Look    at    the    structure    One    in
basis-library/util/one.sml.

The signature is

    sig
       type 'a t

       val make: (unit -> 'a) -> 'a t
       val use: 'a t * ('a -> 'b) -> 'b
    end

The  arg  to  make  is  the creation thunk.  A single copy is made and saved,
along with the thunk and a flag.

When use is called, it checks if the single premade copy is in  use.   If  it
isn't then it passes it to its second arg.  If it is then it makes a new one.

If there isn't  any  contention  then  the  only  expense  (which  should  be
decreased)  are  the  colls  to  Thread.atomicBegin and Thread.atomicEnd.  If
there is then a new copy will be made, which will have to get GC'd, but  that
isn't  a very high price to pay.  It is way better than having to re-allocate
things every time.



More information about the MLton-user mailing list