simple spawning of function as std::thread


In an attempt to inspect code that gcc will generate, I'm trying to do some multi-threaded stuff. A reduced testcase is here:

#include <iostream>
#include <thread>

int  n;
void embiggen(void) { ++n; }

void foo(void)
  std::thread t1(embiggen);
  std::cout << "n = " << n << '\n';

Which of course, generates this failure:

xtools/aarch64-unknown-elf/bin/aarch64-unknown-elf-g++ -ggdb3 -std=c++11 -Wall -Wextra -Wno-unused-parameter -O0 -lpthread -march=armv8.1-a -c foo.o; In function 'void foo()': error: no matching function for call to 'std::thread::thread(void (&)())'
    9 |   std::thread t1(embiggen);
      |                          ^

I believe that I've attempted code like this, and this, to no avail.

Q: What is the incantation to spawn a function as a separate thread?

Read more here:

Content Attribution

This content was originally published by Lance E.T. Compte at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: