Hello, I am trying to implement a `Lock` class to ...
# kotlin-native
m
Hello, I am trying to implement a
Lock
class to act as a mutex, for my
pthread
using code. Is there any example of that? I tried to do it like ktor: https://github.com/ktorio/ktor/blob/master/ktor-utils/posix/src/io/ktor/util/LockNative.kt but it calls functions like
ktor_mutex_create
whose implementation I cannot find. This is my current implementation: https://pastebin.com/THbMhiqD but I'm not sure it's correct. It clearly does something right because my threads don't immediately fail now when I lock with it, but I still get Segmentation Faults sometimes and I think it may be due to my Lock implementation.
You can also use the separate package 'utils' which is published on Bintray. It provides Lock, Condition, AtomicReference and some other stuff.
m
@Arkadii Ivanov the code you linked just has the
expect
classes with no
actual
implementation, where can I find the implementation?
a
They are in sibling source sets, separate for jvm, iOS and Linux
m
Ah thank you, I was looking for the Linux one.
a
Don't forget that native locks have to be destroyed to avoid memory leaks