Hi, this is a subtle error in threading code which creates a race condition.
When the thread is started in the initializer list, it's possible that the run routine will access other members of the instance, before they have enough time to be initialized.
(assignment by = operator in the header, which act as implicit initializer)
In particular, check_quit() may evaluate as true, and thread will immediately stop itself.
A solution is to create the thread in the ctor body, after that all initializers have been processed.
Hi, this is a subtle error in threading code which creates a race condition.
When the thread is started in the initializer list, it's possible that the
run
routine will access other members of the instance, before they have enough time to be initialized. (assignment by = operator in the header, which act as implicit initializer)In particular,
check_quit()
may evaluate as true, and thread will immediately stop itself.A solution is to create the thread in the ctor body, after that all initializers have been processed.