Opened 8 years ago
Last modified 8 years ago
#6223 closed defect
CPLGenerateTempFilename volatite and/or CPLAtomicInc — at Version 1
Reported by: | Kurt Schwehr | Owned by: | Kurt Schwehr |
---|---|---|---|
Priority: | normal | Milestone: | |
Component: | default | Version: | svn-trunk |
Severity: | normal | Keywords: | multithreading |
Cc: |
Description (last modified by )
In r15574, put a volatile modifier on nTempFileCounter. This looks to be protect from multithreaded race cases between callers of CPLGenerateTempFilename where more than one thread might get the same tempfile number. Would it be better to call CPLAtomicInc and use the result of that? If so, should I drop the volatile?
e.g.
static volatile int nTempFileCounter = 0; CPLString osFilename; osFilename.Printf( "%s%u_%d", pszStem, (unsigned int)(CPLGetPID() & 0xFFFFFFFFU), nTempFileCounter++ );
Would become this:
static int nTempFileCounter = 0; CPLString osFilename; osFilename.Printf( "%s%u_%d", pszStem, static_cast<unsigned int>( CPLGetPID() & 0xFFFFFFFFU ), CPLAtomicInc( nTempFileCounter ) );
A second question on this code:
Why the mask on the CPLGetPID()?
Note:
See TracTickets
for help on using tickets.