#Writing a multithreaded application to check for variables while other parts of the code are running
18 messages · Page 1 of 1 (latest)
When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.
Look into atomic types if you're wanting to share an integral type
And some type of mutex if you're wanting to share a class
@rotund goblet is there a way to "multithread" this.
I'm not looking at a massive file that you dump on the server go look stuff up
I think moving if(bigPacket)... out of the void loop would help
void what_you_want_to_do()
{
std::cout << "Do soemthing in a different thread";
}
int main()
{
auto t = std::thread(&what_you_want_to_do);
t.join();
}``` << like this, orrr use `std::jthread`
can you add a whole bunch of code in the "Do something in a different thread"
yeah as much as you want, It also doesn't have to be a whole other function it can be a lambda too and you can pass in variables too like this... ```cpp
void what_you_want_to_do()
{
std::cout << "Do soemthing in a different thread\n";
}
void what_you_want_to_do_2(int x, int y)
{
std::cout << x << y << std::endl;
}
int main()
{
auto t = std::thread(&what_you_want_to_do);
auto t1 = std::thread(&what_you_want_to_do_2, 10, 20);
auto t2 = std::thread([]() {
std::cout << "yet another thread\n";
});
t.join();
t1.join();
t2.join();
}
we're gonna need more info. what exactly are you trying to do?