diff --git a/doc/examples/test_serialization.cpp b/doc/examples/test_serialization.cpp index b690d862..15fbdb19 100644 --- a/doc/examples/test_serialization.cpp +++ b/doc/examples/test_serialization.cpp @@ -75,6 +75,11 @@ auto APU::leaf() -> void { } auto main() -> int { + if(!co_serializable()) { + printf("This implementation does not support serialization\n"); + return 1; + } + Memory::buffer = (uint8_t*)mmap( (void*)0x10'0000'0000, 2 * 65536, PROT_READ | PROT_WRITE | PROT_EXEC, diff --git a/doc/usage.md b/doc/usage.md index dbfc42d6..a3b0f04d 100644 --- a/doc/usage.md +++ b/doc/usage.md @@ -126,6 +126,19 @@ Passing handle of active cothread to this function is not allowed. Passing handle of primary cothread is not allowed. +## co_serializable + +```c +int co_serializable(void); +``` + +Returns non-zero if the implementation keeps the entire coroutine state in the +buffer passed to `co_derive()`. That is, if `co_serializable()` returns +non-zero, and if your cothread does not modify the heap or any process-wide +state, then you can "snapshot" the cothread's state by taking a copy of the +buffer originally passed to `co_derive()`, and "restore" a previous state +by copying the snapshot back into the buffer it came from. + ## co_switch ```c void co_switch(cothread_t cothread);