I want to create a constructor for my thread class which can create a single thread and it should return when the thread starts running at the entry point
Entry point will be some class function which will be passed during run time. Derived class function cannot be changed and it wont update any shared variable which could be checked.
How can I make sure that the pthread I created starts executing at the entry point I specify
That’s is not a good idea.
The constructor of the base class is run first. So if the base class constructor does not return until the thread has reached the entry point then the thread is running inside an object who’s constructor has not run. Thus is completely uninitiated.
If the entry point is a virtual method that is defined in a derived type then you have definitely invoked undefined behavior.
This is also why most threading classes are not designed this way. Usually you create the thread object. Then call a method like
start()which runs a function/method or runable object passed as a parameter. This way you know that the object representing the thread is fully constructed and all members are correctly initialized.