Changes between Version 1 and Version 2 of Ticket #6223


Ignore:
Timestamp:
Nov 16, 2015, 10:05:59 AM (8 years ago)
Author:
Even Rouault
Comment:

+1 for CPLAtomicInc (but use &nTempFileCounter as argument)

I think the mask was when using with some sanitzation runtime because CPLGetPID() could return a value larger than a unsigned int. But A better fix would be to replace %u with CPL_FRMT_GIB and dropping the cast

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #6223 – Description

    v1 v2  
    1 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?
     1In r15574, you 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?
    22
    33e.g.
     
    99                       (unsigned int)(CPLGetPID() & 0xFFFFFFFFU), nTempFileCounter++ );
    1010}}}
    11 Would become this:
     11Would become this.
    1212{{{#!c++
    1313    static int nTempFileCounter = 0;
    1414    CPLString osFilename;
    1515    osFilename.Printf( "%s%u_%d", pszStem,
    16                        static_cast<unsigned int>( CPLGetPID() & 0xFFFFFFFFU ),
    17                        CPLAtomicInc( nTempFileCounter ) );
     16                       static_cast<unsigned int>( CPLGetPID() & 0xFFFFFFFFU),
     17                       CPLAtomicInc(nTempFileCounter) );
    1818}}}
    1919