Fun
0.41.5
The programming language that makes you have fun!
Main Page
Data Structures
Files
File List
Globals
Loading...
Searching...
No Matches
src
vm
os
thread_join.c
Go to the documentation of this file.
1
/*
2
* This file is part of the Fun programming language.
3
* https://fun-lang.xyz/
4
*
5
* Copyright 2025 Johannes Findeisen <you@hanez.org>
6
* Licensed under the terms of the Apache-2.0 license.
7
* https://opensource.org/license/apache-2-0
8
*/
9
10
/**
11
* @file thread_join.c
12
* @brief Implements OP_THREAD_JOIN to wait for a spawned thread and get its result.
13
*
14
* Behavior:
15
* - Pops thread id (int); waits for the thread to finish; pushes the result Value produced by the thread.
16
* - If the thread failed or id is invalid, pushes Nil.
17
*
18
* Errors:
19
* - If argument type is wrong, prints an error and pushes Nil.
20
*/
21
22
case
OP_THREAD_JOIN
: {
23
Value
vtid =
pop_value
(vm);
24
if
(vtid.
type
!=
VAL_INT
) {
25
fprintf
(stderr,
"Runtime type error: thread_join expects thread id (int)\n"
);
26
push_value
(vm,
make_nil
());
27
free_value
(vtid);
28
break
;
29
}
30
Value
res
=
fun_thread_join
((
int
)vtid.
i
);
31
free_value
(vtid);
32
push_value
(vm,
res
);
/* takes ownership */
33
break
;
34
}
OP_THREAD_JOIN
@ OP_THREAD_JOIN
Definition
bytecode.h:152
res
const char * res
Definition
get_string.c:38
Value
Tagged union representing a Fun value.
Definition
value.h:68
Value::i
int64_t i
Definition
value.h:71
Value::type
ValueType type
Definition
value.h:69
fun_thread_join
static Value fun_thread_join(int tid)
Definition
thread_common.c:280
free_value
free_value(vtid)
push_value
push_value(vm, res)
make_nil
Value make_nil(void)
Construct a nil Value.
Definition
value.c:126
VAL_INT
@ VAL_INT
Definition
value.h:51
pop_value
static Value pop_value(VM *vm)
Pop a Value from the VM operand stack.
Definition
vm.c:580
fprintf
#define fprintf
Definition
vm.c:200
Generated on
for Fun by
1.16.1