Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rust子线程调用Call或者call_without_args 发生崩溃 #25

Closed
liujingxuan opened this issue Nov 14, 2024 · 7 comments
Closed

rust子线程调用Call或者call_without_args 发生崩溃 #25

liujingxuan opened this issue Nov 14, 2024 · 7 comments

Comments

@liujingxuan
Copy link

在rust中创建子线程,调用Call或者call_without_args崩溃,异常堆栈如下:
11-14 17:43:43.285 19505-19588 C03F00/com.qun...s/ArkCompiler com.qunar.hos F [default] [CheckThread:207] Fatal: ecma_vm cannot run in multi-thread! thread:19593 currentThread:19588 11-14 17:43:43.285 19505-19588 C03F00/MUSL-SIGCHAIN com.qunar.hos E signal_chain_handler call 2 rd sigchain action for signal: 6 sca_sigaction=5a97b29874 noreturn=0 FREEZE_signo_6 thread_list_lock_status:-1 tl_lock_count=0 tl_lock_waiters=0 tl_lock_tid_fail=-1 tl_lock_count_tid=-1
通过查找,这个函数可能没有使用napi_call_threadsafe_function,还是我使用又问题啊。
`pub fn call_noargs_arkts_func(method:String) ->String{
let global_runtime_clone = Arc::clone(&GLOBAL_RUNTIME);
let mut runtime_guard = global_runtime_clone.lock().unwrap();
if runtime_guard.is_none() {
*runtime_guard = Some(ArkRuntime::new().unwrap());
}
let runtime = runtime_guard.as_ref().unwrap();
let module = runtime.load_with_info("entry/src/main/ets/Test", "com.example.qptest/entry").unwrap();
let ret: String = module.call_without_args::<_, String>(&method).unwrap();
return ret;

}`

Copy link

@richerfu Please check this issue, thanks.

@richerfu
Copy link
Member

新版本加入了对 env 调用的多线程检测导致崩溃。实际上示例代码在之前的版本是个擦边球的实现,加载的模块和函数不能跨线程调用。

@liujingxuan
Copy link
Author

好的好的,感谢啊。那我如何在rust子线程中调用arkts代码呢

@liujingxuan
Copy link
Author

初始化和加载Module放到主线程,call方法调用放到子线程是否可行呢

@richerfu
Copy link
Member

均在子线程执行即可。

@liujingxuan
Copy link
Author

好的好的,感谢啊,我画蛇添足了。每次新new runtime就行了。二维码过期了,可以更新下吗

@richerfu
Copy link
Member

richerfu commented Nov 14, 2024

已更新
晚些时候更新示例

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants