paulgked
paulgked

Reputation: 77

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)?

Upvotes: 6

Views: 191

Answers (2)

Sergio.Uma
Sergio.Uma

Reputation: 52

clock_nanosleep is the POSIX compliant version to sleep for an interval on a high resolution clock, see man page, for example on http://linux.die.net/man/2/clock_nanosleep for details.

Upvotes: 0

seamaner
seamaner

Reputation: 91

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.

Upvotes: 2

Related Questions