1
0
mirror of https://github.com/SoftEtherVPN/SoftEtherVPN.git synced 2026-02-11 13:10:08 +03:00

Fix data race on Tick64

Add lock protection when reading/writing Halt flag to prevent data race.
This commit is contained in:
synqa
2026-02-01 12:26:41 +09:00
parent 68e9f0b593
commit fe460de5a6

View File

@ -139,6 +139,7 @@ void Tick64Thread(THREAD *thread, void *param)
{ {
UINT tick; UINT tick;
UINT64 tick64; UINT64 tick64;
bool halt;
#ifndef OS_WIN32 #ifndef OS_WIN32
tick = TickRealtime(); // Get the current system clock tick = TickRealtime(); // Get the current system clock
@ -228,7 +229,13 @@ void Tick64Thread(THREAD *thread, void *param)
n = 0; n = 0;
} }
if (tk64->Halt) Lock(tk64->TickLock);
{
halt = tk64->Halt;
}
Unlock(tk64->TickLock);
if (halt)
{ {
break; break;
} }
@ -286,7 +293,11 @@ void FreeTick64()
} }
// Termination process // Termination process
Lock(tk64->TickLock);
{
tk64->Halt = true; tk64->Halt = true;
}
Unlock(tk64->TickLock);
Set(halt_tick_event); Set(halt_tick_event);
WaitThread(tk64->Thread, INFINITE); WaitThread(tk64->Thread, INFINITE);
ReleaseThread(tk64->Thread); ReleaseThread(tk64->Thread);