simple spawning of function as std::thread

Comrades!

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);
  t1.join();
  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 foo.cc -c foo.o;
foo.cc: In function 'void foo()':
foo.cc:9:26: 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: https://stackoverflow.com/questions/68473800/simple-spawning-of-function-as-stdthread

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: