swesterfeld / spectmorph

SpectMorph: spectral audio morphing
http://www.spectmorph.org
GNU Lesser General Public License v2.1
64 stars 5 forks source link

Fix variables accessed in thread before initialization #5

Closed jpcima closed 4 years ago

jpcima commented 4 years ago

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.

swesterfeld commented 4 years ago

Good point. I've merged your code without changes. Thanks!