Threads, vectors and references in C++11 on OS X

I was trying to compile some C++ of the form

std::vector<std::thread> threads;
for (int i = 0; i<num_threads; ++i)
   threads.push_back(std::thread(logisticTest, kmer_lines[i], samples);

with function prototype

void logisticTest(Kmer& k, const std::vector<Sample>& samples);

on OS X 10.10 with clang++ – Apple LLVM version 6.0 (clang-600.0.54) (based on LLVM 3.5svn)

First error message: no matching function for call to ‘__invoke’
Solution: add ‘-std=c++11 -stdlib=libc++’ to CXXFLAGS in Makefile
(thanks to

Second error message: attempt to use a deleted function __invoke(_VSTD::move(_VSTD::get<0>(__t)), _VSTD::mov…
Solution: pass to thread by value rather than reference. e.g.

std::reference_wrapper: threads.push_back(std::thread(logisticTest, std::ref(kmer_lines[i]), std::cref(samples)));

(thanks to

  1. Booooo. You should be using GCC, the GNU Compiler Collection.

    • jofunu6 said:

      Ha, true!
      I will be eventually, but I need to get it to work on both in the end

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s