void NetworkLoop(std::future<bool> condition)
// Messeage sending procedure
auto SendMessage = (constchar* message)
std::cout << message << std::endl;
// main thread will signal end of program to this thread trough this variable
auto status = std::future_status::deferred;
// Keep sending packets until program exit every 2 seconds
while (status != std::future_status::ready)
status = condition.wait_for(std::chrono::seconds(2));
// Create communication channel between this and network thread
std::future<bool> condition = promise.get_future();
// Create network thread
std::thread network(NetworkLoop, std::move(condition));
// Main program runs for 10 seconds
// it does nothing special by default but it could so here...
// Tell network thread to stop
// Join thread
std::cout << "Program is finished!" << std::endl;
another way is, if you already have like a main loop in your main program code, just put a timer there, and if enough time has passed, do the activity.
that changes the loop to
get current time
if current time - last time > time to wait
send keep alive message
update last time
single threaded programs are starting to be a thing of the past, but if you were on an embedded system with 1 cpu or something, or just starting out and don't want to tackle threading yet, etc this will do it.
text eds are often threaded now, mixed bag on those.
quantum computers are so far past the end of my life I can't worry about it :) But many things will go out of scope. A lot of security goes out the window, in theory.
as I understand the theory (which is not well) they can do anything the old fashioned way, its just not ideal for the hardware.