Segmentation fault in other thread. I create threa...
# kotlin-native
l
Segmentation fault in other thread. I create thread using native linux functions: pthread_create(threadId.ptr, null, funRun, stableRef.asCPointer()) pthread_join(threadId.value, null), but if I call nativeHeap.alloc(...) or userdata, then I get Segmentation fault error
I solved problem. Need statement in new thread -konan.initRuntimeIfNeeded()
s
Please note that passing object between threads is currently possible only when you explicitly transfer them using workers API (https://github.com/JetBrains/kotlin-native/blob/master/runtime/src/main/kotlin/konan/worker/Worker.kt).
Also some details are available in “workers” sample: https://github.com/JetBrains/kotlin-native/blob/master/samples/workers/README.md
l
Svyatoslav, I see this worker, but it don't solve many tasks with thread, therefore I use native threads
s
Could you please provide more details? An example of task not solvable by workers?
l
I tried to rewrite using Worker, but I have a error after the successful completion function. Error: /home/jetbrains/kotlin-native-release/runtime/src/main/cpp/Memory.cpp980 runtime assert: Memory leaks found
s
Please try to add
future.consume { ... }
before worker termination.
l
Thanks, It works! Can I implement the function mutex for the operation? ex. pthread_mutex_lock(acceptMutex); val rc = FCGX_Accept_r(request.ptr); pthread_mutex_unlock(acceptMutex)
s
Could you please clarify your question?
l
Svyatoslav, thank you for your answers. I want enforcing limits on access to a resource or function (eg. FCGX_Accept_r(request.ptr)). Usually in the c language use mutex (I see in Worker kotlin object - locker). How can I synchronize access to a resource or functions within a body Worker?