Serene Runtime 1.0.0-dev
C runtime for the Serene programming language
Loading...
Searching...
No Matches
hello.c
Go to the documentation of this file.
1/* -*- C -*-
2 * Serene programming language
3 * Copyright (C) 2019-2026 Sameer Rahmani <[email protected]>
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17 */
18
19// Hello world for an external program that links libserene.runtime built with
20// -Dwith-serene=disabled. It uses only the substrate: the memory manager, the
21// engine/context, and the fiber subsystem. No value model, no LLVM.
22
23#include <stdio.h>
24
25#include "serene/runtime.h"
26
27// A shared sentinel result. Returning null would be legal too.
28static int ok;
29
31 (void)ctx;
32 (void)arg;
33 printf("hello from a Serene fiber (substrate runtime)\n");
34 return &ok;
35}
36
37int main(void) {
38 SERENE_RUNTIME_INIT_WITH_SCHED(engine, sched, nullptr);
39 srn_context_t *ctx = srn_context_make(engine);
40
41 (void)srn_fiber_make(ctx, sched, say_hello, NULL, 0);
42 srn_sched_run(sched, 1);
43
44 // The manager reclaims every context chain at shutdown, so the context
45 // needs no separate release here.
47 return 0;
48}
static srn_fiber_result_t say_hello(srn_context_t *ctx, void *arg)
Definition 01_hello.c:34
static int ok
Definition hello.c:28
static srn_fiber_result_t say_hello(srn_context_t *ctx, void *arg)
Definition hello.c:30
int main(void)
Definition hello.c:37
srn_context_t * srn_context_make(srn_engine_t *engine)
Make an empty context, by allocating a new memory block.
Definition context.c:39
srn_fiber_t * srn_fiber_make(srn_context_t *ctx, srn_scheduler_t *sched, const char *name, srn_fiber_entry_t entry, void *arg, size_t stack_size)
Create a fiber that will run entry(ctx, arg), registered with sched but NOT scheduled.
Definition fiber.c:201
void * srn_fiber_result_t
What a fiber's entry produces, type-erased.
Definition fiber.h:157
#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