emscripten-core / emscripten-core/emscripten
Proper way to call asyncify_start_unwind and other Asyncify functions from C?
- Dominant language
- C++
- Stars
- 27.6k
- Forks
- 3.6k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 105
Description
I'm trying to call the various asyncify functions to allow users to have a main() function which yields out, waiting for animation, based on this https://kripken.github.io/blog/wasm/2019/07/16/asyncify.html - But, I can't seem to get those symbols to link via emcc.
I'm assuming this is the preferred method of doing async code at this time from C.
Here is my C code:
```
struct stack_unwind
{
void * start;
void * stop;
} UNW;
void asyncify_start_unwind( struct stack_unwind * );
void asyncify_stop_unwind();
void asyncify_stop_rewind();
void asyncify_start_rewind( struct stack_unwind * );
extern void jssleep();
int is_sleeping = 0;
void csleep()
{
writeoutStr( "csleep A" );
if( is_sleeping )
{
asyncify_stop_rewind();
is_sleeping = 0;
}
else
{
is_sleeping = 1;
UNW.stop = UNW.start + 1000;
asyncify_start_unwind( &UNW );
jssleep();
}
writeoutStr( "csleep B" );
}
void internalmain()
{
writeoutStr( "internalmain A" );
csleep();
writeoutStr( "internalmain B" );
}
void testmain()
{
int i;
UNW.start = &i;
writeoutStr( "testmain A" );
internalmain();
writeoutStr( "testmain B" );
// asyncify_stop_unwind();
writeoutStr( "testmain C" );
// asyncify_start_rewind( &UNW );
writeoutStr( "testmain D" );
internalmain();
writeoutStr( "testmain E" );
}
```
When I try compiling it, I get this:
```
emcc -o cfile.wasm cfile.c watfile.wasm -s EXPORTED_FUNCTIONS='["_testcallback","_add2","_animationFrame", "_testmain","_csleep", "_asyncify_stop_unwind", "_asyncify_start_rewind","_asyncify_start_unwind","_asyncify_stop_rewind"]' -s EXPORTED_RUNTIME_METHODS='["ccall","cwrap"]' -s ERROR_ON_UNDEFINED_SYMBOLS=0 -s ASYNCIFY=1
warning: undefined symbol: asyncify_start_rewind (referenced by top-level compiled C/C++ code)
warning: undefined symbol: asyncify_start_unwind (referenced by top-level compiled C/C++ code)
warning: undefined symbol: asyncify_stop_rewind (referenced by top-level compiled C/C++ code)
warning: undefined symbol: asyncify_stop_unwind (referenced by top-level compiled C/C++ code)
warning: undefined symbol: beginPath (referenced by top-level compiled C/C++ code)
warning: undefined symbol: canvasClear (referenced by top-level compiled C/C++ code)
warning: undefined symbol: jssleep (referenced by top-level compiled C/C++ code)
warning: undefined symbol: stroke (referenced by top-level compiled C/C++ code)
warning: undefined symbol: tackSegment (referenced by top-level compiled C/C++ code)
warning: undefined symbol: writeout (referenced by top-level compiled C/C++ code)
warning: undefined symbol: writeoutStr (referenced by top-level compiled C/C++ code)
```
Despite the asyncify specification. And it does indeed fail to find it when trying to run.
Contributor guide
Assessment
This issue has not been assessed yet.