From: Tyler Retzlaff Date: Thu, 10 Mar 2022 07:35:08 +0000 (-0800) Subject: eal/windows: fix data race when creating threads X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=e4e983b975df700474309605b6adb5f2c6d83e2f;p=dpdk.git eal/windows: fix data race when creating threads eal_thread_loop() uses lcore_config[i].thread_id, which is stored upon the return from CreateThread(). Per documentation, eal_thread_loop() can start before CreateThread() returns and the ID is stored. Create lcore worker threads suspended and then subsequently resume to allow &lcore_config[i].thread_id be stored before eal_thread_loop execution. Fixes: 53ffd9f080fc ("eal/windows: add minimum viable code") Cc: stable@dpdk.org Signed-off-by: Tyler Retzlaff Acked-by: Dmitry Kozlyuk --- diff --git a/lib/eal/windows/eal_thread.c b/lib/eal/windows/eal_thread.c index 54fa93fa62..ff84cb42af 100644 --- a/lib/eal/windows/eal_thread.c +++ b/lib/eal/windows/eal_thread.c @@ -150,13 +150,18 @@ eal_thread_create(pthread_t *thread) th = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)(ULONG_PTR)eal_thread_loop, - NULL, 0, (LPDWORD)thread); + NULL, CREATE_SUSPENDED, (LPDWORD)thread); if (!th) return -1; SetPriorityClass(GetCurrentProcess(), NORMAL_PRIORITY_CLASS); SetThreadPriority(th, THREAD_PRIORITY_NORMAL); + if (ResumeThread(th) == (DWORD)-1) { + (void)CloseHandle(th); + return -1; + } + return 0; }