File: join-thread.md

package info (click to toggle)
bordeaux-threads 0.9.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 672 kB
  • sloc: lisp: 4,765; makefile: 2
file content (60 lines) | stat: -rw-r--r-- 1,492 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
---
date: 2022-01-07T08:00:00Z
title: 'Function JOIN-THREAD'
weight: 7
---

#### Syntax:

**join-thread** thread => multiple values

#### Arguments and values:

*thread* -> a [thread](../class-thread) object.

#### Description

Wait until `thread` terminates, or if it has already terminated,
return immediately.

The return values of the thread function are returned.

#### Examples


```
(let ((thread (bt2:make-thread
               (lambda () (values 1 2 3)))))
  (bt2:join-thread thread))

```
=> 1, 2, 3

#### Exceptional situations:

If a thread is terminated by an unhandled condition, or by
[**destroy-thread**](../destroy-thread), then the condition
[**abnormal-exit**](../abnormal-exit) is signaled.

#### See also:

[**make-thread**](./make-thread),
[**abnormal-exit**](../abnormal-exit)

#### Notes:

Due to how **join-thread** interacts with the dynamic environment
established by **make-thread**, it is not safe to join with a thread
that was created outside Bordeaux-Threads. For example, the following
code has undefined behaviour and might very well corrupt the image:

```
(mapcar #'bt2:join-thread (bt2:all-threads))
```

Bordeaux-Threads can only record instances of thread termination due
to unhandled conditions or the use of
[**destroy-thread**](../destroy-thread). In case of other ways to
terminate a thread, such as throwing to an implementation-specific tag
defined in the dynamic environment of the thread function, the
behaviour of **join-thread** is undefined.