Skip to content

Commit

Permalink
ae.sys.file: Use a shared counter in tempFileNameExtension
Browse files Browse the repository at this point in the history
Avoid issues due to TID reuse and TLS lifetimes.
  • Loading branch information
CyberShadow committed Jul 18, 2024
1 parent 6aa8594 commit 27dbf31
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions sys/file.d
Original file line number Diff line number Diff line change
Expand Up @@ -2831,6 +2831,7 @@ auto pushd(string dir)

// ****************************************************************************

import core.atomic : atomicOp;
import std.algorithm;
import std.process : thisProcessID;
import std.traits;
Expand All @@ -2840,12 +2841,12 @@ import ae.utils.meta;
/// Returns a unique file name (suited for a temporary file) based on `target`.
string tempFileNameExtension(string target)
{
static int counter;
static shared int counter;
return "%s.%s.%s.%s.temp".format(
target,
thisProcessID,
getCurrentThreadID,
counter++,
counter.atomicOp!"+="(1),
);
}

Expand Down

0 comments on commit 27dbf31

Please sign in to comment.