The source code comes from Adam Dunkels' Protothreads.
MODULE.bazel
bazel_dep(name = "protothreads", version = "<version>")See Releases
BUILD
cc_binary(
...
deps = [
"@protothreads//:pt",
],
)main.c
#include <pt/pt.h>
PT_THREAD(thread1(pt_t *pt)) {
PT_BEGIN(pt);
PT_END(pt);
}
int main() {
pt_t pt_1;
PT_INIT(&pt_1);
while (PT_SCHEDULE(thread1(&pt_1))) {
}
return 0;
}See also example.
Uses the C switch() statement to resume execution of a function
bazel build --define=pt_option=lc_switch appbazel build //example:examples
bazel test //test:unit_test
# For MSVC
bazel build --config=msvc //example:examples
bazel test --config=msvc //test:unit_test