wasm-micro-runtime
wasm-micro-runtime copied to clipboard
pthread_cond_timedwait
we use pthread_cond_timedwait as below, using wasi-sdk build is okay #include "tizen_api.h" #include <stdio.h> #include <pthread.h> pthread_mutex_t lock; pthread_cond_t cond;
void *thread_routine(void *arg) { printf("Enter thread\n"); int ret = 0; int count = 0; while(count < 20) { count++; pthread_mutex_lock(&lock); pthread_cond_timedwait(&cond, &lock, 500000); pthread_mutex_unlock(&lock);
}
pthread_exit(NULL);
return NULL;
}
int main(int argc, char **argv) { pthread_mutex_init(&lock, NULL); pthread_cond_init(&cond, NULL); pthread_t tid;
if (0 != pthread_create(&tid, NULL, thread_routine, NULL)) {
printf("Failed to create thread\n");
}
if (0 != pthread_join(tid, NULL)) {
printf("Failed to join thread %d.\n", tid);
}
pthread_cond_destroy(&cond);
pthread_mutex_destroy(&lock);
printf("Exit\n");
return 0;
} but when run pop up below error [02:31:20:054 - B60FDE40]: failed to check signature '(**I)i' and resolve pointer params for import function (env pthread_cond_timedwait) it means the parameter type mismatch ?
Hi, which pthread.h
are you using? the prototype of API pthread_cond_timedwait
in wamr is here:
https://github.com/bytecodealliance/wasm-micro-runtime/blob/e80715f352b2cb18f63cdfa067a743766a0b7f66/wamr-sdk/app/libc-builtin-sysroot/include/pthread.h#L45-L46
The third argument is an uint64 integer due to current limitation
Could you please use the pthread.h
provided by WAMR (under wamr-sdk/app/libc-builtin-sysroot/include/pthread.h
, you can copy it to /opt/wasi-sdk/share/wasi-sysroot/include
) and try again?
we have use add "--sysroot=wamr-sdk/app/libc-builtin-sysroot/" when build the third parameter is "I" so 500000 is not right?
That's strange, did you see any warning during compilation ?
You can use wasm-objdump -x xxx.wasm
to check the actual signature of the pthread_cond_timedwait
function