<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: icpc - Thread_local an classes with &amp;quot;constructor = default&amp;quot; leads to multiple call to in Intel® oneAPI DPC++/C++ Compiler</title>
    <link>https://community.intel.com/t5/Intel-oneAPI-DPC-C-Compiler/icpc-Thread-local-an-classes-with-quot-constructor-default-quot/m-p/1648668#M4232</link>
    <description>&lt;P&gt;Little update, by removing "=default" and replacing by "{}" the destructor will only be called once.&lt;/P&gt;</description>
    <pubDate>Wed, 11 Dec 2024 11:13:22 GMT</pubDate>
    <dc:creator>johanM</dc:creator>
    <dc:date>2024-12-11T11:13:22Z</dc:date>
    <item>
      <title>icpc - Thread_local an classes with "constructor = default" leads to multiple call to destructor</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-DPC-C-Compiler/icpc-Thread-local-an-classes-with-quot-constructor-default-quot/m-p/1648666#M4231</link>
      <description>&lt;P&gt;Hi,&lt;BR /&gt;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&amp;nbsp; : 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.&lt;BR /&gt;&lt;BR /&gt;I have made a simple example of it:&lt;/P&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="cpp"&gt;#include &amp;lt;iostream&amp;gt;
#include &amp;lt;thread&amp;gt;

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;
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;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.&lt;BR /&gt;&lt;BR /&gt;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.&lt;BR /&gt;&lt;BR /&gt;Can someone explain/fix this? It seems it is not fixed on latest icpc versions.&lt;BR /&gt;&lt;BR /&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Wed, 11 Dec 2024 11:10:38 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-DPC-C-Compiler/icpc-Thread-local-an-classes-with-quot-constructor-default-quot/m-p/1648666#M4231</guid>
      <dc:creator>johanM</dc:creator>
      <dc:date>2024-12-11T11:10:38Z</dc:date>
    </item>
    <item>
      <title>Re: icpc - Thread_local an classes with "constructor = default" leads to multiple call to</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-DPC-C-Compiler/icpc-Thread-local-an-classes-with-quot-constructor-default-quot/m-p/1648668#M4232</link>
      <description>&lt;P&gt;Little update, by removing "=default" and replacing by "{}" the destructor will only be called once.&lt;/P&gt;</description>
      <pubDate>Wed, 11 Dec 2024 11:13:22 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-DPC-C-Compiler/icpc-Thread-local-an-classes-with-quot-constructor-default-quot/m-p/1648668#M4232</guid>
      <dc:creator>johanM</dc:creator>
      <dc:date>2024-12-11T11:13:22Z</dc:date>
    </item>
    <item>
      <title>Re: icpc - Thread_local an classes with "constructor = default" leads to multiple call to</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-DPC-C-Compiler/icpc-Thread-local-an-classes-with-quot-constructor-default-quot/m-p/1648733#M4233</link>
      <description>&lt;P&gt;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)&lt;/P&gt;</description>
      <pubDate>Wed, 11 Dec 2024 16:59:20 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-DPC-C-Compiler/icpc-Thread-local-an-classes-with-quot-constructor-default-quot/m-p/1648733#M4233</guid>
      <dc:creator>Viet_H_Intel</dc:creator>
      <dc:date>2024-12-11T16:59:20Z</dc:date>
    </item>
  </channel>
</rss>

