rust-spice icon indicating copy to clipboard operation
rust-spice copied to clipboard

Thread Safety

Open mkalte666 opened this issue 4 years ago • 0 comments

The c library is, as far as i know, not thread safe. Thus using anything currently provided by this library (be it wrapped or not) also is not. However, functions like spice::str2et can be called from different threads. That breaks stuff.

I am, for now, using this ugly ugly ugly thing to keep stuff from breaking for me:

https://github.com/mkalte666/satwatch/blob/2545d4d980104fe35527f14b8494385258a157b9/src/libspace/src/spice_lock.rs#L1

I think it would be nice to be forced to call something like spice::new() returning an object that provides the whole api. Users can then wrap it in an arc to keep being able to put stuff into other threads, being forced to use proper synchronization.

It seems like a bit of a niche case, but at least making sure users don't end up with weird errors cause they don't know they cant access stuff from other threads seems like a good idea to me. I might be missing something somewhere, so if thats the case, id be happy to be corrected and have that pointed out for me.

In any case, have a good weekend :D

mkalte666 avatar Jan 28 '22 19:01 mkalte666