I was interested in implementing a library like malbolgia myself, I'll look at 
the source code, the locker implementation is what I need.

The following works:
    
    
    import malebolgia
    import malebolgia / lockers
    
    type Example = object
        s: string
        c: int
    
    proc threadFunc(lockedObj: Locker[Example]) =
        lock lockedObj as obj:
            obj.s.add($obj.c)
            inc obj.c
    
    proc threadHandler() =
        var m = createMaster()
        var ex: Example
        var myObj = initLocker(ex)
        
        m.awaitAll:
            for i in 0..4:
                m.spawn threadFunc(myObj)
        
        lock myObj as obj:
            echo obj
    
    echo "Work"
    threadHandler()
    echo "Done."
    
    
    Run

I thought passing `ref` to Threads worked as [the nim memory 
model](https://nim-lang.org/docs/mm.html) says that ORC has a shared heap.

I think understand well how Nim deals with memory, what I don't understand is 
how this interacts with threads.

But this is good as I plan to create a PR to add more documentation comments to 
the standard library and I feel like [the typed thread 
page](https://nim-lang.org/2.0.2/typedthreads.html) needs an update. 

Reply via email to