#How do I use jthread?

3 messages · Page 1 of 1 (latest)

drifting eagle
#

I would like to be able to use a jthread in a program I'm working on and also to better understand how to use library features. Here is some code I've tried testing it with by commenting and uncommenting some of the macros.

#include <iostream>

#undef _GLIBCXX_HAS_GTHREADS
#define _GLIBCXX_HAS_GTHREADS true
//#define __cpp_lib_jthread
#include <version>
#include <stop_token>
//#define __cpp_lib_jthread
#include <thread>

#define log(x) std::cout << x << std::endl;

using namespace std;


int main() {
    jthread j ([&] { 
        log("lmao");
        b = false;
    });
}
worldly widget
#

Hi, I would recommend you this video https://www.youtube.com/watch?v=Kj3F_7DFB0A and also https://en.cppreference.com/w/cpp/thread/jthread for better understanding

fresh craneBOT
#

@drifting eagle

This question thread is being automatically closed. If your question is not answered feel free to bump the post or re-ask. Take a look at !howto ask for tips on improving your question.