Is FSBlockDeviceResource (and other FSResources) thread-safe?

Is FSBlockDeviceResource thread-safe, or do I need to ensure that it’s not written across multiple threads simultaneously? I see that FSBlockDeviceResource is not marked as Sendable in Swift.

(This question could also apply to the other FSResources as well if it's simple to answer for them too, but it's just that for my specific use case I'm using FSBlockDeviceResource.)

Answered by Systems Engineer in 891115022

I think the question I'm hearing is if you need to exercise any concurrency concerns around FSBlockDeviceResource.

The functions on the objects are thread safe, and you should really only have one instance of an FSBlockDeviceResource. Put it in a var on your file system or volume object and reference it as needed.

Internally, it manages state for your process relative to that device. Among other things, if someone yanks the disk, the object terminates itself and closes the underlying file descriptor.

Accepted Answer

I think the question I'm hearing is if you need to exercise any concurrency concerns around FSBlockDeviceResource.

The functions on the objects are thread safe, and you should really only have one instance of an FSBlockDeviceResource. Put it in a var on your file system or volume object and reference it as needed.

Internally, it manages state for your process relative to that device. Among other things, if someone yanks the disk, the object terminates itself and closes the underlying file descriptor.

Is FSBlockDeviceResource (and other FSResources) thread-safe?
 
 
Q