yglukhov / nimx

GUI library
MIT License
1.09k stars 75 forks source link

[Threads] how to use threads with it? #404

Closed Dev1lroot closed 4 years ago

Dev1lroot commented 4 years ago

import os, nimx/window, nimx/text_field

var wnd = newWindow(newRect(40, 40, 800, 600)) let label = newLabel(newRect(20, 20, 150, 20)) wnd.addSubview(label)

proc mywhile() = var i = 0 while(true): label.text = $i i = i + 1 os.sleep(1000)

var th1: Thread[void]

createThread(th1, mywhile)

th1.joinThread()

proc main() = echo "just run, don't bother"

runApplication: main()

-_-

yglukhov commented 4 years ago

This is a Nim question, nimx is nothing special in these regards. Please, read the nim manual, and/or ask around e.g. on the nim forum.

yglukhov commented 4 years ago

But generally you can't access same refs from different threads. I'd suggest messaging approach.