The wait function is OK. It's the main loop logic that is not right. The
do...while
loop has nothing to break it as the
wait
function is outside the loop.
This should work:
int main ()
{
using namespace jsw::threading;
int option{};
auto_event e;
LPVOID args[2] = { &option, &e };
thread worker = thread::start (get_option, args);
system ("cls");
do {
if (e.wait (5000))
{
switch (option) {
case 1: break;
case 2: break;
case 3: break;
default: std::cout << "Option not valid!" << std::endl;
break;
}
}
else
{
std::cout << "Timeout!" << std::endl;
option = 0; }
} while (option != 3);
std::cout << "***Program Exit***" << std::endl;
worker.abort (NO_ERROR);
std::cout << "***PROGRAM END***\n";
}