@@ -4,31 +4,31 @@ weight = 2
4template = "doc.html"
4template = "doc.html"
7−Here's a simple example of a thread that starts another thread:
7+Here's a simple example of a thread that starts another thread:
9−### parent.hoon
9+#### `parent.hoon`
13/+ *strandio
13/+ *strandio
14=, strand=strand:spider
14=, strand=strand:spider
15−^- thread:spider
15+^- thread:spider
16−|= arg=vase
16+|= arg=vase
17−=/ m (strand ,vase)
17+=/ m (strand ,vase)
19;< tid=tid:spider bind:m (start-thread %child)
19;< tid=tid:spider bind:m (start-thread %child)
20(pure:m !>(~))
20(pure:m !>(~))
23−### child.hoon
23+#### `child.hoon`
27/+ *strandio
27/+ *strandio
28=, strand=strand:spider
28=, strand=strand:spider
29−^- thread:spider
29+^- thread:spider
30−|= arg=vase
30+|= arg=vase
31−=/ m (strand ,vase)
31+=/ m (strand ,vase)
33%- (slog leaf+"foo" ~)
33%- (slog leaf+"foo" ~)
34(pure:m !>(~))
34(pure:m !>(~))
@@ -48,7 +48,7 @@ foo
48;< tid=tid:spider bind:m (start-thread %child)
48;< tid=tid:spider bind:m (start-thread %child)
51−See here how we gave `start-thread` the name of the thread to run. It returns the `tid` of the thread, which we could then use to poke it or whatever.
51+See here how we gave `start-thread` the name of the thread to run. It returns the `tid` of the thread, which we could then use to poke it or whatever.
53`start-thread` handles creating the `tid` for the thread so is quite convenient.
53`start-thread` handles creating the `tid` for the thread so is quite convenient.
@@ -58,15 +58,15 @@ Note that threads we start this way will be a child of the thread that started t
59If we want to actually get the result of the thread we started, it's slightly more complicated:
59If we want to actually get the result of the thread we started, it's slightly more complicated:
61−### parent.hoon
61+#### `parent.hoon`
65/+ *strandio
65/+ *strandio
66=, strand=strand:spider
66=, strand=strand:spider
67−^- thread:spider
67+^- thread:spider
68−|= arg=vase
68+|= arg=vase
69−=/ m (strand ,vase)
69+=/ m (strand ,vase)
71;< =bowl:spider bind:m get-bowl
71;< =bowl:spider bind:m get-bowl
72=/ tid `@ta`(cat 3 'strand_' (scot %uv (sham %child eny.bowl)))
72=/ tid `@ta`(cat 3 'strand_' (scot %uv (sham %child eny.bowl)))
@@ -84,7 +84,7 @@ If we want to actually get the result of the thread we started, it's slightly mo
87−### child.hoon
87+#### `child.hoon`
@@ -94,9 +94,9 @@ If we want to actually get the result of the thread we started, it's slightly mo
95++ url "https://www.whatsthelatestbasehash.com/"
95++ url "https://www.whatsthelatestbasehash.com/"
97−^- thread:spider
97+^- thread:spider
98−|= arg=vase
98+|= arg=vase
99−=/ m (strand ,vase)
99+=/ m (strand ,vase)
101;< =cord bind:m (fetch-cord url)
101;< =cord bind:m (fetch-cord url)
102=/ hash-as-cord `@t`(end [3 (sub (met 3 cord) 1)] cord)
102=/ hash-as-cord `@t`(end [3 (sub (met 3 cord) 1)] cord)
@@ -104,7 +104,7 @@ If we want to actually get the result of the thread we started, it's slightly mo
104(pure:m !>(hash))
104(pure:m !>(hash))
107−`child.hoon` simply grabs the latest base hash from https://www.whatsthelatestbasehash.com/ and returns it.
107+`child.hoon` simply grabs the latest base hash from https://www.whatsthelatestbasehash.com/ and returns it.
109`parent.hoon` is a bit more complicated so we'll look at it line-by-line
109`parent.hoon` is a bit more complicated so we'll look at it line-by-line
@@ -136,10 +136,10 @@ We pre-emptively subscribe for the result. Spider sends the result at `/thread-r
137Spider takes a poke with a mark %spider-start and a vase containing `[parent=(unit tid) use=(unit tid) file=term =vase]` to start a thread, where:
137Spider takes a poke with a mark %spider-start and a vase containing `[parent=(unit tid) use=(unit tid) file=term =vase]` to start a thread, where:
139−* `parent` is an optional parent thread. In this case we say the parent is our tid. Specifying a parent means the child will be killed if the parent ends.
139+- `parent` is an optional parent thread. In this case we say the parent is our tid. Specifying a parent means the child will be killed if the parent ends.
140−* `use` is the thread ID for the thread we're creating
140+- `use` is the thread ID for the thread we're creating
141−* `file` is the filename of the thread we want to start
141+- `file` is the filename of the thread we want to start
142−* `vase` is the vase it will be given as an argument when it's started
142+- `vase` is the vase it will be given as an argument when it's started
145;< =cage bind:m (take-fact /awaiting/[tid])
145;< =cage bind:m (take-fact /awaiting/[tid])
@@ -164,15 +164,15 @@ Finally we test whether the thread produced a `%thread-done` or a `%thread-fail`
165## Stop a thread
165## Stop a thread
167−### parent.hoon
167+#### `parent.hoon`
171/+ *strandio
171/+ *strandio
172=, strand=strand:spider
172=, strand=strand:spider
173−^- thread:spider
173+^- thread:spider
174−|= arg=vase
174+|= arg=vase
175−=/ m (strand ,vase)
175+=/ m (strand ,vase)
177;< =bowl:spider bind:m get-bowl
177;< =bowl:spider bind:m get-bowl
178=/ tid `@ta`(cat 3 'strand_' (scot %uv (sham %child eny.bowl)))
178=/ tid `@ta`(cat 3 'strand_' (scot %uv (sham %child eny.bowl)))
@@ -193,7 +193,7 @@ Finally we test whether the thread produced a `%thread-done` or a `%thread-fail`
193(pure:m !>("Done"))
193(pure:m !>("Done"))
196−### child.hoon
196+#### `child.hoon`
@@ -213,8 +213,8 @@ Finally we test whether the thread produced a `%thread-done` or a `%thread-fail`
215^- thread:spider
215^- thread:spider
216−|= arg=vase
216+|= arg=vase
217−=/ m (strand ,vase)
217+=/ m (strand ,vase)
219;< ~ bind:m looper
219;< ~ bind:m looper
220(pure:m !>(~))
220(pure:m !>(~))
@@ -232,6 +232,6 @@ Finally we test whether the thread produced a `%thread-done` or a `%thread-fail`
235−* `%spider-stop` is the mark that tells spider to kill a thread.
235+- `%spider-stop` is the mark that tells spider to kill a thread.
236−* `tid` is the tid of the thread to kill
236+- `tid` is the tid of the thread to kill
237−* `%.y` tells spider to suppress traceback in the result of the killed thread. If you give it `%.n` it will include the traceback.
237+- `%.y` tells spider to suppress traceback in the result of the killed thread. If you give it `%.n` it will include the traceback.