In C++, I have this sample implementation:
#include <thread>
#include <iostream>
void doSomeWork( void )
{
std::cout << "hello from thread..." << std::endl;
while(true)
{
printf("Getting inside doSomeWork\n");
sleep(1);
}
}
int main( int argc, char *argv[] )
{
std::thread t( doSomeWork );
t.join();
processing();
return 0;
}
void processing()
{
while(true)
{
printf("Getting inside processing\n");
sleep(1);
}
}
I have a problem that doSomeWork() keep doing things and it block processing(). I thought thread is asynchronous so that while it is sleeping, I can other things. My question here is how can I sleep in doSomeWork() and yield other threads, then resume doSomework()?