linux sleeping with clock_nanosleep

前端 未结 4 1050
自闭症患者
自闭症患者 2021-02-09 13:10

I want to use clock_nanosleep for waiting of 1 microsec.. As far as I understand, I have to give an absolute time as input. Is the following code okay in this case?

<         


        
4条回答
  •  花落未央
    2021-02-09 13:51

    @ryanyuyu

    sample code::

    void mysleep_ms(int milisec)
    {
        struct timespec res;
        res.tv_sec = milisec/1000;
        res.tv_nsec = (milisec*1000000) % 1000000000;
        clock_nanosleep(CLOCK_MONOTONIC, 0, &res, NULL);
    }
    

    this is monotonic clock based sleep function. please refer it.

提交回复
热议问题