Serene Runtime 1.0.0-dev
C runtime for the Serene programming language
Loading...
Searching...
No Matches
01_hello.c File Reference
#include <stdio.h>
#include <serene/runtime.h>
Include dependency graph for 01_hello.c:

Go to the source code of this file.

Functions

static srn_fiber_result_t say_hello (srn_context_t *ctx, void *arg)
int main (void)

Function Documentation

◆ main()

int main ( void )

Definition at line 41 of file 01_hello.c.

41 {
42 // The memory manager and the engine come up in one step; the engine
43 // creates one scheduler at startup and `sched` is bound to it.
44 SERENE_RUNTIME_INIT_WITH_SCHED(engine, sched, nullptr);
45 srn_context_t *ctx = srn_context_make(engine);
46
47 // Create the fiber. It is registered and made ready, but nothing runs until
48 // the scheduler does.
49 srn_fiber_t *fiber = srn_fiber_spawn(ctx, say_hello, nullptr);
50
51 // Drive the scheduler on this one thread. It returns once the fiber has run
52 // and the ready queue is empty.
53 srn_sched_run(sched, 1);
54
55 printf("fiber finished in state %d\n", (int)fiber->state);
56
59 return 0;
60}
static srn_fiber_result_t say_hello(srn_context_t *ctx, void *arg)
Definition 01_hello.c:34
srn_context_t * srn_context_make(srn_engine_t *engine)
Make an empty context, by allocating a new memory block.
Definition context.c:39
int srn_context_release(srn_context_t *ctx)
Definition context.c:64
srn_fiber_t * srn_fiber_spawn(srn_context_t *ctx, srn_fiber_entry_t entry, void *arg)
Make and schedule a fiber with every default, the engine's scheduler, the configured stack size,...
Definition fiber.c:247
#define SERENE_RUNTIME_SHUTDOWN(engine)
Tear down what SERENE_RUNTIME_INIT brought up, in reverse order, the engine (reactor,...
Definition runtime.h:58
#define SERENE_RUNTIME_INIT_WITH_SCHED(engine, sched, config)
SERENE_RUNTIME_INIT plus a sched variable bound to the engine's scheduler, which every run and fiber ...
Definition runtime.h:46
void srn_sched_run(srn_scheduler_t *sched, size_t nworkers)
Run the scheduler with nworkers os threads draining it, returning once the pool goes quiescent (every...
Definition scheduler.c:843
_Atomic srn_fiber_state_t state
The lifecycle state.
Definition fiber.h:273
Here is the call graph for this function:

◆ say_hello()

srn_fiber_result_t say_hello ( srn_context_t * ctx,
void * arg )
static

Definition at line 34 of file 01_hello.c.

34 {
35 (void)ctx;
36 (void)arg;
37 printf("hello from a fiber\n");
38 return nullptr;
39}
Here is the caller graph for this function: