Hi Leute,
ich check mal wieder gar nichts. Bei folgendem Beispiel aus dem Buch:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | #include <future> #include <thread> #include <chrono> #include <random> #include <iostream> #include <exception> using namespace std; // enable synchronized output with print() mutex printMutex; void print(const string& str) { lock_guard<mutex> l(printMutex); for(char c: str) { cout.put(c); } cout << endl; } int main() { auto f1 = async(launch::async, print, "Hello from a first thread"); auto f2 = async(launch::async, print, "Hello from a second thread"); print("Hello from the main thread"); } |
...wird die Thread-Bib wirgendwie nicht richtig gelinkt??
Ich kompilier wie gewohnt mit:
1 | g++ sixth_exmpl.cpp -o ex6.o -std=c++11 -pthread |
Und bekomm dann bei Ausführung:
1 2 3 | terminate called after throwing an instance of 'std::system_error' what(): Enable multithreading to use std::thread: Operation not permitted Aborted (core dumped) |
Wäre für Hilfe dankbar.
Moderiert von rklm:
Bitte nur eine Frage pro Thema.