[physfs] Multithreading / MSYS compilation

Ryan C. Gordon icculus at icculus.org
Sat Jan 9 23:08:48 EST 2010


> May an opened archive only be accessed from a thread?

That is thread-safe. PhysicsFS protects accesses to archives with a 
mutex, so you can access a given archive from any thread at any time.

It is not thread safe, however, to use the same PHYSFS_file from two 
threads at the same time. Doing so is almost always a bug anyhow, so we 
didn't put any thread safety into those.

Two threads can operate on two different PHYSFS_file objects at the same 
time (even if those PHYSFS_files both refer to the same file in the same 
archive), though, and will not be serialized with a mutex, so they both 
run at full speed.

> An abstracted file cannot be opened twice generally?

If you have to read from the same file from two threads at the same 
time, it IS safe to open it twice with PHYSFS_openRead(), and then have 
each thread process its own PHYSFS_file.

> Or may a PHYSFS_File descriptor not be used simultaneously, but opening
> a file twice will work?

Yes, that is correct.

> http://icculus.org/pipermail/physfs/2009-July/000757.html . Perhaps a
> notice or new patch release could help others to avoid this. Or have i
> overlooked something?

This is fixed in revision control, but there hasn't been an official 
PhysicsFS release with the fix:

    http://hg.icculus.org/icculus/physfs/rev/13f24148b2bb

--ryan.




More information about the physfs mailing list