- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
we have in our code some thread_local homemade containers in order to don't reallocate them at each call of thread function, and recently we added "=default" in a constructor instead of "{}", and this result in a strange behavior : at the end of the thread, the destructor began to be called as much as the function was called inside the thread, and as we have a free on a pointer in the destructor the application began to crash on "double free" error.
I have made a simple example of it:
#include <iostream>
#include <thread>
class youpela{
float toto{};
public:
constexpr youpela() noexcept = default;
~youpela(){
printf("delete_youpela\n");
// Here if I free a pointer : double delete if my_func was called at least twice
}
};
void my_func()
{
thread_local youpela boom;
printf("leaving my_func()\n");
}
void my_thread_func()
{
my_func();
my_func();
}
int main()
{
printf("main\n");
std::thread my_thread(my_thread_func);
my_thread.join();
return 0;
}
And on compiler explorer, this behavior is only observable by using icc (icpc in our case). GCC/icx don't have this behavior the constructor is only called once, instead of twice with icpc.
This behavior is clearly not expected, and in our case we call a lot of time this method, resulting in a huge loop on destruction for each threads I guess.
Can someone explain/fix this? It seems it is not fixed on latest icpc versions.
Thanks
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Little update, by removing "=default" and replacing by "{}" the destructor will only be called once.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Intel C++ Compiler Classic (icc/icpc) has been end of life. We will not fix or release a new version of icc/icpc any more. Please migrate your code to oneAPI DPC++/C++ Compiler (icx/icpx)

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page