ac8b25935f
- Add async/await/spawn keywords to lexer - C runtime: pthread wrappers (bux_task_spawn, bux_task_join, bux_task_sleep) - C runtime: mutex/condvar channel implementation (bux_channel_new/send/recv/close/free) - Build command adds -pthread flag for C compilation - Std::Task module: TaskHandle, Task_Spawn, Task_Join, Task_Sleep - Std::Channel module: generic Channel<T> with Send, Recv, Close, Free - Parser: spawn Expr() expression - Sema: ekSpawn returns *void - HIR: hSpawn node lowered from ekSpawn - C backend: emit bux_task_spawn(FuncName, arg) for spawn expressions - Example: examples/concurrency.bux (thread + channel demo) - Example: examples_pkg/concurrency working project
36 lines
858 B
Plaintext
36 lines
858 B
Plaintext
module Std::Channel {
|
|
|
|
extern func bux_channel_new(capacity: int64, elem_size: int64) -> *void;
|
|
extern func bux_channel_send(handle: *void, elem: *void);
|
|
extern func bux_channel_recv(handle: *void, out: *void) -> int;
|
|
extern func bux_channel_close(handle: *void);
|
|
extern func bux_channel_free(handle: *void);
|
|
|
|
struct Channel<T> {
|
|
handle: *void;
|
|
}
|
|
|
|
func Channel_New<T>(capacity: int64) -> Channel<T> {
|
|
return Channel<T> { handle: bux_channel_new(capacity, sizeof(T)) };
|
|
}
|
|
|
|
func Channel_Send<T>(ch: *Channel<T>, value: T) {
|
|
bux_channel_send(ch.handle, &value);
|
|
}
|
|
|
|
func Channel_Recv<T>(ch: *Channel<T>) -> T {
|
|
var result: T;
|
|
bux_channel_recv(ch.handle, &result);
|
|
return result;
|
|
}
|
|
|
|
func Channel_Close<T>(ch: *Channel<T>) {
|
|
bux_channel_close(ch.handle);
|
|
}
|
|
|
|
func Channel_Free<T>(ch: *Channel<T>) {
|
|
bux_channel_free(ch.handle);
|
|
}
|
|
|
|
}
|