+ 1

What happens if we make a thread in heap using new, join it, and delete it using delete?

15th Jul 2016, 11:33 PM
_Geometry dash_ _Roh_ (AKA NovaRate0315)
_Geometry dash_ _Roh_ (AKA NovaRate0315) - avatar
2 Answers
+ 1
Depends on how you exit it, what library you are using etc. The C++11 standard library header <thread> is known to have problems. One of the problematic behaviors that is considered to be a bug by now but was approved by committee at time of standard creation is the execution of exit() in the destructor. This might seem insane by now, as exit rather ends the process but at that time the committee wanted to make sure that as long as the C++ thread object is not detached from the operating system thread there is no behavior that leads to hanging programs on close.
16th Jul 2016, 12:34 AM
Stefan
Stefan - avatar
0
Btw, for many cases it's better to use a task in C++11 and above.
16th Jul 2016, 1:25 AM
Stefan
Stefan - avatar