Avoid using sleep_for on Windows
@@ -608,6 +608,7 @@ void StressUploadLockMultiThreaded(ILogConfiguration& config)
while (numIterations--)
{
+ ILogger *result = LogManager::Initialize(TEST_TOKEN, config);
// Keep spawning UploadNow threads while the main thread is trying to perform Initialize and Teardown
while (threadCount++ < MAX_THREADS)
{
@@ -615,13 +616,16 @@ void StressUploadLockMultiThreaded(ILogConfiguration& config)
{
std::this_thread::yield();
LogManager::UploadNow();
- const auto randTimeSub2ms = std::chrono::milliseconds(std::rand() % 2);
- std::this_thread::sleep_for(randTimeSub2ms);
+ const auto randTimeSub2ms = std::rand() % 2;
+ // I believe we might be hitting an issue with std::this_thread::sleep_for on Windows with msvc++ runtime
+ // Ref.:
+ // https://developercommunity.visualstudio.com/content/problem/58530/bogus-stdthis-threadsleep-for-implementation.html
+ // The solution for Win32 is that PAL::sleep uses Win32 API instead of C++11 sleep.
+ PAL::sleep(randTimeSub2ms);
threadCount--;
});
t.detach();
};
- ILogger *result = LogManager::Initialize(TEST_TOKEN, config);
EventProperties props = CreateSampleEvent("event_name", EventPriority_Normal);
result->LogEvent(props);
LogManager::FlushAndTeardown();
