Rust requires some invariants must uphold for threads. For example, all arguments passed to thread must be Send. When using std::thread and third-party crates, this invariants are checked by compiler.
Unfortunately, in my case, I have to use native threading (like clone() or pthread_create).
So, my question is: what invariants apply to limits?
Note that std::thread
is implemented with pthreads on all unix-like platforms.
If you make direct clone
or pthread_create
calls, this is unsafe FFI, and it's up to you to enforce relevant safety. I would suggest wrapping these calls with your own functions that require T: Sync
and/or T: Send
as appropriate, so the compiler can enforce that for you.
2 Likes