Skip to content

Commit

Permalink
eal/windows: fix data race when creating threads
Browse files Browse the repository at this point in the history
[ upstream commit e4e983b ]

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: 53ffd9f ("eal/windows: add minimum viable code")

Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
Acked-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
  • Loading branch information
Tyler Retzlaff authored and steevenlee committed Jun 15, 2022
1 parent 3a9281f commit 5888f84
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/librte_eal/windows/eal_thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,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;
}

Expand Down

0 comments on commit 5888f84

Please sign in to comment.