Reputation: 433
I was reading libstdc++-v3 std::thread
implementation and I saw that a unique_ptr is released after the thread is created, so when it runs out of scope, the memory that is potentially used by the new thread isn't deallocated. (https://github.com/gcc-mirror/gcc/blob/6b1633378b74bed1d999a0ae2549088515a30ba0/libstdc%2B%2B-v3/src/c%2B%2B11/thread.cc#L152). As far as I'm concerned, one must manually delete the manual pointer later, but I can't find where that is done. Help?
Upvotes: 1
Views: 66
Reputation: 433
Nvm, just found.
https://github.com/gcc-mirror/gcc/blob/6b1633378b74bed1d999a0ae2549088515a30ba0/libstdc%2B%2B-v3/src/c%2B%2B11/thread.cc#L81
It casts a void*
to a thread::_State*
to a thread::_State_ptr
(which is the actual std::unique_ptr) to use RAII. This code style is a bit unreadable imo. I thought about deleting the question, but gonna leave it here in case anyone is interested
Upvotes: 1