Modernes C++ programmieren

Okt 23, 2024

lst-1004-book.cpp

// https://godbolt.org/z/Kv84eb96E 
#include <iostream>
#include <thread>
#include <chrono>
using namespace std::chrono; // seconds, suffix s
auto makeThread(std::string wer) {
    return std::jthread{ [wer] {
        std::this_thread::sleep_for(1s);
        std::cout << "Viel Glueck, " << wer << std::endl;
    } };
}
int main() {
    auto th = makeThread("Jim"); // Ausgabe: Viel Glueck, Jim
    th.join();
}