# HG changeset patch # User Alain Mazy # Date 1764673396 -3600 # Node ID 5541a6b13500d42f8a09529cbb7722fe845aedd9 # Parent ef77a536195b64ac7738ef22126d7e24e56b4160 avoid possible duplicate thread names diff -r ef77a536195b -r 5541a6b13500 OrthancServer/Sources/ServerJobs/ArchiveJob.cpp --- a/OrthancServer/Sources/ServerJobs/ArchiveJob.cpp Tue Dec 02 12:02:19 2025 +0100 +++ b/OrthancServer/Sources/ServerJobs/ArchiveJob.cpp Tue Dec 02 12:03:16 2025 +0100 @@ -56,6 +56,8 @@ static const char* const KEY_ARCHIVE_SIZE = "ArchiveSize"; static const char* const KEY_TRANSCODE = "Transcode"; +static boost::mutex loaderThreadsCounterMutex; +static uint32_t loaderThreadsCounter = 0; namespace Orthanc { @@ -251,8 +253,11 @@ static void PreloaderWorkerThread(ThreadedInstanceLoader* that) { - static uint16_t threadCounter = 0; - Logging::SetCurrentThreadName(std::string("ARCH-LOAD-") + boost::lexical_cast(threadCounter++)); + { + boost::mutex::scoped_lock lock(loaderThreadsCounterMutex); + Logging::SetCurrentThreadName(std::string("ARCH-LOAD-") + boost::lexical_cast(loaderThreadsCounter++)); + loaderThreadsCounter %= 1000000; + } LOG(INFO) << "Loader thread has started"; diff -r ef77a536195b -r 5541a6b13500 OrthancServer/Sources/ServerJobs/ThreadedSetOfInstancesJob.cpp --- a/OrthancServer/Sources/ServerJobs/ThreadedSetOfInstancesJob.cpp Tue Dec 02 12:02:19 2025 +0100 +++ b/OrthancServer/Sources/ServerJobs/ThreadedSetOfInstancesJob.cpp Tue Dec 02 12:03:16 2025 +0100 @@ -31,6 +31,10 @@ #include #include +static boost::mutex instanceWorkerThreadsCounterMutex; +static uint32_t instanceWorkerThreadsCounter = 0; + + namespace Orthanc { static const char* EXIT_WORKER_MESSAGE = "exit"; @@ -244,9 +248,11 @@ void ThreadedSetOfInstancesJob::InstanceWorkerThread(ThreadedSetOfInstancesJob* that) { - static uint16_t threadCounter = 0; - Logging::SetCurrentThreadName(std::string("JOB-INS-WORK-") + boost::lexical_cast(threadCounter++)); - threadCounter %= 1000; + { + boost::mutex::scoped_lock lock(instanceWorkerThreadsCounterMutex); + Logging::SetCurrentThreadName(std::string("JOB-INS-WORK-") + boost::lexical_cast(instanceWorkerThreadsCounter++)); + instanceWorkerThreadsCounter %= 1000; + } while (true) {