Well, I've tried adding locks, but I removed them to keep it simple in the 
example. This is one of my other attempts, but this still gives errors: 
`'myThread' is not GC-safe as it accesses 'data' which is a global using GC'ed 
memory`
    
    
    import os
    import locks
    
    var myLock: Lock
    initLock(myLock)
    var data  {.guard: myLock.} : seq[string]
    data.add("Test")
    
    proc myThread() {.thread.} =
        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)
    echo data[1]
    
    
    Run

Compiled with the following args: `nim c -d:mingw --cpu:amd64 --threads:on 
--gc:arc --tlsEmulation:on .\test.nim`

Reply via email to