NO

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

Offline vanatic

  • Member
  • *
  • Posts: 2
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: 1968
    • 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

Offline vanatic

  • Member
  • *
  • Posts: 2
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  :)