Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make a thread wake up and suspend for 500ms continuously in C

I am using multiple threads in my program. I want a specific thread to be waken up after 500ms. How can I do that without using a usleep(500)?

like image 338
paulgked Avatar asked Dec 18 '15 03:12

paulgked


People also ask

How do you suspend a thread for a period of time?

sleep(time): This is a method used to sleep the thread for some milliseconds time. suspend(): This is a method used to suspend the thread.

Which method is used to suspend pause a thread temporarily?

Java Thread suspend() method The suspend() method of thread class puts the thread from running to waiting state. This method is used if you want to stop the thread execution and start it again when a certain event occurs. This method allows a thread to temporarily cease execution.


1 Answers

The socket API like select can be used as a timer.

struct timeval tv;
tv.tv_sec = 0;
tv.tv_usec = 500;
select(0, NULL, NULL, NULL, &tv);

You may need this choice.

like image 74
seamaner Avatar answered Sep 30 '22 11:09

seamaner