Skip to content
Tcl Source Code View Ticket
Login

View Ticket

Inconsistent locking during zipfs initialization

Opence32712f83f0d30051adb6a53e11f9e338a9944fCreated 1 year agoUpdated 359 days ago
Descriptionmarkdown2025-10-03 10:04:51

Both the following sequences are seen in tclZipFs.c

    ReadLock();
    if (!ZipFS.initialized) {
	ZipfsSetup();
    }

and

    WriteLock();
    if (!ZipFS.initialized) {
	ZipfsSetup();
    }
  • Why is ZipfsSetup under a read lock in some cases and write locks in others? Does not seem to make sense.
  • How is a read lock sufficient given that ZipfsSetup modifies the internal structures?

I had added a TODO comment questioning this when fixing zipfs bugs during the 9.0 beta but forgot to revisit and just saw it today :-(

dkfmarkdown2025-10-07 14:11:25

Since it's a once-per-process setup, the flag is likely set to true before the process launches any more threads (that read the vfs). The different locks may be for the code that follows.

If my thoughts are correct, moving the call to ZipfsSetup() outside the lock (and having it recheck the flag inside the call as well as using its own lock, for double-checked locking) is likely to be the optimal approach; the case when two threads vie of the new lock is expected to be very rare.

The memory barrier due to the function call is probably enough.

jan.nijtmanswiki2025-12-09 09:01:27

Ping? What's the status of this?

Log in (anonymous is fine) to add a comment.