I was able to make it work by adding `{.cast(gcsafe).}:`, instructing the 
compiler that this block is GCSafe, so it won't bother checking.
    
    
    import os
    import std/tables
    import threadpool
    import locks
    
    var myLock: Lock
    initLock(myLock)
    var data  {.guard: myLock.} : seq[string]
    data.add("Test")
    
    proc myThread() {.thread.} =
        {.cast(gcsafe).}:
            echo "Start of new thread"
            withLock myLock:
                echo data[0]
                data.add("I want to access this from the main thread!")
                echo "End of new thread"
    
    echo "Start"
    
    echo type(data.addr)
    var thread: Thread[void]
    createThread[void](thread, myThread)
    joinThreads(thread)
    echo "Thread done. Trying to access second string from seq:"
    sleep(500)
    withLock myLock:
        echo data[1]
    
    
    Run

Reply via email to