Zth (libzth)
Loading...
Searching...
No Matches
9_c_api.c

C-API example.

C-API example.

/*
* SPDX-FileCopyrightText: 2019-2026 Jochem Rutgers
*
* SPDX-License-Identifier: CC0-1.0
*/
// Default Zth header include.
#include <zth.h>
#include <stdio.h>
// In constrast to C++, fiber entry function must have type void(void*). There
// is no need to do zth_fiber() and friends, just use zth_fiber_create() to run
// the fiber.
void fiber(void* UNUSED_PAR(arg))
{
printf("fiber()\n");
}
int main_fiber(int UNUSED_PAR(argc), char** UNUSED_PAR(argv))
{
printf("main_fiber()\n");
// Start a new fiber, with arg=NULL, default stack, and no name.
zth_fiber_create(fiber, NULL, 0, NULL);
return 0;
}
int main_fiber(int argc, char **argv)
Definition main.cpp:11
int zth_fiber_create(void(*f)(void *), void *arg=nullptr, size_t stack=0, char const *name=nullptr) noexcept
Run a function as a new fiber.
Definition async.h:834
#define UNUSED_PAR(name)
Definition macros.h:78