Using std::thread ends up with "pure virtual method cal

Hi,

I am trying to use the C++11 feature std::thread on my Ubuntu 17.04 box.
Here is my simple helloworld program:

#include <thread>
#include <iostream>
#include <cstdlib>

void mythread(void* d)
{
  std::cout << "Hello from thread!" << std::endl;
}
         
int main()
{
  std::thread t(std::thread(mythread, nullptr));
  t.join();
  return EXIT_SUCCESS;
}

I compile this simple test with PGI pgc++ 16.10-0 64-bit target on x86-64 Linux -tp haswell using the following command:

  $ pgc++ test.cpp -o test -std=c++11 -lpthread

No error is printed but when I run the code, here is what I get:

  pure virtual method called
  terminate called without an active exception
  Abandon (core dumped)

What am I missing? Is there a library I should link my binary with?

For information, my box has gcc 4.9.2 and this is what ldd test prints:

        linux-vdso.so.1 =>  (0x00007fffa73b5000)
        libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f0228217000)
        libpgatm.so => /opt/pgi/linux86-64/16.10/lib/libpgatm.so (0x00007f0228012000)
        libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f0227d03000)
        libpgmp.so => /opt/pgi/linux86-64/16.10/lib/libpgmp.so (0x00007f0227a83000)
        libnuma.so => /opt/pgi/linux86-64/16.10/lib/libnuma.so (0x00007f0227881000)
        libpgc.so => /opt/pgi/linux86-64/16.10/lib/libpgc.so (0x00007f02275f9000)
        libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f02272f1000)
        libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f0226f26000)
        libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f0226d10000)
        /lib64/ld-linux-x86-64.so.2 (0x000055e3522fe000

Not sure the PGI libstdc++ is used here.
/opt/pgi/linux86-64/16.10/lib is the first entry in my LD_LIBRARY_PATH.


Thanks very much,

J.D.P

Hello. First of all, you need to make sure the gcc version is 5.2 or better.
gcc 4.4.7 will fail because it lacks the lib support pgc++ needs.

% g++ -o test_g++ test.cpp -std=c++0x -lpthread
% icc -o test_intel test.cpp -std=c++0x -lpthread
% pgc++ -std=c++0x -o test_pgi test.cpp -lpthread

all create executables.

test_g++ | test_intel | test_pgi
all result in

Hello from thread!

dave

Dave,

Thanks for this information. I didn’t know gcc 5.2 was needed.
Do you know if this is documented somewhere?

Best,
JDP

We need a g++ that supports C++11 and C++14 features in order
for pgc++ to also support them - gcc headers and libs need to be right.

Release Notes

PGI Câ� +â� + Compiler â—¦ Integrated EDG release 4.13 and enabled interoperability with GCC 5.2, 5.3, 5.4, 6.0, 6.1, 6.2, and 6.3. To take full advantage of the new Câ� +â� +â� 11 features supported by GCC 5.1 and later, use the PGCâ� +â� + compiler option --câ� +â� +â� 11.
â—¦ Comprehensive support for Câ� +â� +â� 14; co-installation with GCC version 5.0 or greater is required. Enable Câ� +â� +â� 14 features with the PGCâ� +â� + compiler option --câ� +â� +â� 14.
â—¦ Added Câ� +â� +â� 11 support to PGCâ� +â� +â� when PGCâ� +â� + is used as the nvcc host compiler; this support requires a patched post-CUDA-8.0-production version of nvcc. Contact sales@pgroup.com for more information.

dave