eal/windows: fix data race when creating threads
PATCH 1/1 eal/windows: fix data race when creating threads
create lcore worker threads suspended and then subsequently resume to allow &lcore_config[i].thread_id be stored before eal_thread_loop execution.
--- lib/eal/windows/eal_thread.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
lib/eal/windows/eal_thread.c +6 -1
@@ -150,13 +150,18 @@ 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 ; }
Signature · 1 line
1.8.3.1
Hi Tyler,
2022-03-09 23:35 (UTC-0800), Tyler Retzlaff:
Quoted 9 lines
create lcore worker threads suspended and then subsequently resume to allow &lcore_config[i].thread_id be stored before
eal_thread_loopexecution.Signed-off-by Tyler Retzlaff <[email protected]>
It takes some effort to correlate &lcore_config[i].thread_id with the code in the patch and knowledge of CreateThread() to understand the root cause.
I suggest prepending an explanation to your commit message:
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.
Quoted 28 lines
--- lib/eal/windows/eal_thread.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)lib/eal/windows/eal_thread.c +6
-1@@ -150,13 +150,18 @@ 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 ; }
Thomas Monjalon
Applied10/03/2022 17:19, Dmitry Kozlyuk:
Quoted 20 lines
Hi Tyler,
2022-03-09 23:35 (UTC-0800), Tyler Retzlaff:
Quoted 9 lines
create lcore worker threads suspended and then subsequently resume to allow &lcore_config[i].thread_id be stored before
eal_thread_loopexecution.Signed-off-by Tyler Retzlaff <[email protected]>Acked-by Dmitry Kozlyuk <[email protected]>It takes some effort to correlate &lcore_config[i].thread_id with the code in the patch and knowledge of
CreateThread()to understand the root cause.
I suggest prepending an explanation to your commit message:
Quoted 4 lines
eal_thread_loop()uses lcore_config[i].thread_id, which is stored upon the return fromCreateThread(). Per documentation,eal_thread_loop()can start beforeCreateThread()returns and the ID is stored.
There was now reply to this suggestion after 3 weeks, so I've decided to include it.
Applied, thanks.