The source code comes from Adam Dunkels' Protothreads.
MODULE.bazel
bazel_dep(name = "protothreads")
git_override(
module_name="protothreads",
remote="https://github.com/JalonWong/protothreads.git",
branch="main",
)
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 app
bazel build //example:examples
bazel test //test:unit_test