NO

Author Topic: thrd_sleep did not sleep for .tv_sec [PellesC 9.00.9]  (Read 2592 times)

vanatic

  • Guest
thrd_sleep did not sleep for .tv_sec [PellesC 9.00.9]
« on: September 16, 2018, 02:49:06 PM »
thrd_sleep() did not sleep as expected, if .tv_sec > 0

Code: [Select]
#include <threads.h>
#include <time.h>
#include <stdio.h>

int main(void)
{
    printf("ctime: %s", ctime(&(time_t){time(NULL)}));
    printf("sleep: %d\n", thrd_sleep(&(struct timespec){.tv_sec=1}, NULL));
    printf("ctime: %s", ctime(&(time_t){time(NULL)}));
    printf("sleep: %d\n", thrd_sleep(&(struct timespec){.tv_sec=1,.tv_nsec=1}, NULL));
    printf("ctime: %s", ctime(&(time_t){time(NULL)}));
    printf("sleep: %d\n", thrd_sleep(&(struct timespec){.tv_nsec=999999999}, NULL));
    printf("ctime: %s", ctime(&(time_t){time(NULL)}));
}

Offline Pelle

  • Administrator
  • Member
  • *****
  • Posts: 2266
    • http://www.smorgasbordet.com
Re: thrd_sleep did not sleep for .tv_sec [PellesC 9.00.9]
« Reply #1 on: September 16, 2018, 07:37:45 PM »
Confirmed.
/Pelle

vanatic

  • Guest
Re: thrd_sleep did not sleep for .tv_sec [PellesC 9.00.9]
« Reply #2 on: September 17, 2018, 05:57:10 PM »
I think it is not worth to mention, but it seems the problem is in newly introduced _nanosleep(), it looks like thrd_sleep() using it  :)