wasm-micro-runtime icon indicating copy to clipboard operation
wasm-micro-runtime copied to clipboard

Android mult-thread pthread_exit crash

Open JakeOrange opened this issue 5 months ago • 11 comments

I am debugging the casehello_world.wasm.zip on Android. I instantiated the wasm module. I called the function _start. It will create 10 threads. After wasm_func_call executed successfully,pthread_exit crashed.

截屏2024-02-06 21 39 41

JakeOrange avatar Feb 06 '24 14:02 JakeOrange

what is the value of maximum number of threads?

lum1n0us avatar Feb 08 '24 02:02 lum1n0us

12

JakeOrange avatar Feb 08 '24 06:02 JakeOrange

I run it ok on MacOS and iOS.

JakeOrange avatar Feb 08 '24 06:02 JakeOrange

In that case, I would suggest setting max_thread_num of RuntimeInitArgs to a larger number, like 12 or 15, then using wasm_runtime_full_init() to start everything.

lum1n0us avatar Feb 18 '24 00:02 lum1n0us

In that case, I would suggest setting max_thread_num of RuntimeInitArgs to a larger number, like 12 or 15, then using wasm_runtime_full_init() to start everything.

I had set CLUSTER_MAX_THREAD_NUM to 12. And MacOS and iOS is rightly. Are there other points?

JakeOrange avatar Feb 19 '24 02:02 JakeOrange

iwasm works well with the hello_world.wasm on my local environment. Could u try it, with iwasm, on MacOS?

$ ./iwasm --max-threads=20 ./hello_world.wasm
 in thread 4
 in thread 7
 in thread 6
 in thread 2
 in thread 3
 in thread 9
 in thread 5
 in thread 0
 in thread 8
 in thread 1

lum1n0us avatar Feb 19 '24 11:02 lum1n0us

iwasm works well with the hello_world.wasm on my local environment. Could u try it, with iwasm, on MacOS?

$ ./iwasm --max-threads=20 ./hello_world.wasm
 in thread 4
 in thread 7
 in thread 6
 in thread 2
 in thread 3
 in thread 9
 in thread 5
 in thread 0
 in thread 8
 in thread 1

I had set CLUSTER_MAX_THREAD_NUM to 12. And MacOS and iOS is rightly. Are there other points?

I had try it on MacOS, it is OK. It only happen on Android. And it must happen.

JakeOrange avatar Feb 19 '24 12:02 JakeOrange

I had try it on MacOS, it is OK. It only happen on Android. And it must happen.

When reproduce it on Android, using iwasm or your local, self compiled, wamr library?

lum1n0us avatar Feb 19 '24 13:02 lum1n0us

I had try it on MacOS, it is OK. It only happen on Android. And it must happen.

When reproduce it on Android, using iwasm or your local, self compiled, wamr library?

Compile locally to .so with cmake

JakeOrange avatar Feb 20 '24 02:02 JakeOrange

Since I can't reproduce it locally, here are some BKMs of the team, hope useful:

  • Don't mix using WAMR_BUILD_LIB_PTHREAD and WAMR_BUILD_LIB_PTHREAD together
  • With the help of valgrind and sanitizers(WAMR_BUILD_SANITIZER)
  • Shrink the problem by break something. For example:
    • try variant thread numbers
    • try variant compilation options, like BOUND_CHECK
    • comment wasm_deinstantiate()
    • comment wasm_unload()
    • ...

lum1n0us avatar Feb 21 '24 08:02 lum1n0us

Since I can't reproduce it locally, here are some BKMs of the team, hope useful:

Get it. Thanks!

JakeOrange avatar Feb 21 '24 08:02 JakeOrange