What Can I Use Besides usleep in a Modern POSIX Environment?

前端 未结 5 1570
一向
一向 2021-01-19 05:04

I\'m fairly new to C but writing a small multithreaded application. I want to introduce a delay to a thread. I\'d been using \'usleep\' and the behavior is what I desire -

5条回答
  •  南方客
    南方客 (楼主)
    2021-01-19 06:09

    Did you have the #include ?.

    And you can use some of the similar methods instead: nanosleep() for nanoseconds and sleep() for seconds. Or another way could be using clock(), but i think this is more CPU wasting.

提交回复
热议问题