1
0
mirror of https://github.com/janet-lang/janet synced 2024-09-30 16:00:40 +00:00
janet/examples/threads.janet
Calvin Rose 8f31a53276 Add thread example.
Also remove reference to pthread_t in the JanetThread structure.
2019-12-01 20:47:22 -06:00

19 lines
401 B
Plaintext

(defn worker-main
[parent]
(def name (thread/receive parent))
(for i 0 10
(os/sleep 1)
(print "thread " name " wakeup no. " i))
(thread/send parent :done))
(defn make-worker
[name]
(-> (thread/new make-image-dict) (thread/send worker-main) (thread/send name)))
(def bob (make-worker "bob"))
(os/sleep 0.5)
(def joe (make-worker "joe"))
(thread/receive bob)
(thread/receive joe)