mirror of
https://github.com/janet-lang/janet
synced 2025-10-23 11:47:40 +00:00
Add thread example.
Also remove reference to pthread_t in the JanetThread structure.
This commit is contained in:
18
examples/threads.janet
Normal file
18
examples/threads.janet
Normal file
@@ -0,0 +1,18 @@
|
||||
(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)
|
Reference in New Issue
Block a user