Race condition in TThread
Original Reporter info from Mantis: pavel.bazika
-
Reporter name: Pavel Bazika
Original Reporter info from Mantis: pavel.bazika
- Reporter name: Pavel Bazika
Description:
When Resume is called from inside of constructor of TThread and LFreeOnTerminate is set to true, there is a race condition, when the thread frees the object intance before constrcutor is finished and therefore before AfterConstruction is called. Because AfterConstruction is virtual method, object instance must exist to vmt be valid.
I propose a patch for unix rtl version, but because AfterConstruction is declared to be rtl-wide, it is incomplete.
To AfterConstruction method should be added statement:
CurrentTM.SemaphorePost(FInitialSem);
Steps to reproduce:
- Inherit from TThread, override constructor
- Into the body of constructor insert
LFreeOnTerminate:=True;
Resume;
Sleep(1000);
- Leave default Execute method (=empty)
- The crash will occur when jump to AfterConstruction will be tried.
Mantis conversion info:
- Mantis ID: 20345
- Platform: Linux
- Version: 2.4.4