Pelles C > Bug reports
Possible thread bug?
John Z:
This program uses thrd_sleep under 9.00.9 and 10.00.6. have I made a mistake?
Used C11 and multihread.lib, no optimize, level 2 , console program. Tried C17, and multithread dll too.
--- Code: ---#include <threads.h>
#include <time.h>
#include <stdio.h>
int main(void)
{
printf("Time: %s", ctime(&(time_t){time(NULL)}));
thrd_sleep(&(struct timespec){.tv_sec=15}, NULL); // sleep 15 sec
printf("Time: %s", ctime(&(time_t){time(NULL)}));
}
--- End code ---
The clock should show 15 seconds difference but it appears thrd_sleep does not sleep.
Actually time.h is included in threads.h so that is redundant - but not a problem....
Any thoughts?
John Z
Update: I found and tried _nanosleep instead, it DOES work but the time is limited in total to less than 100,000,001 nanoseconds, even though there is a sec input. If set sec to 1 then an error results.
Update2: Well …. it seems thrd_sleep seems to have the same .1 second limitation ??? Why do the structures have tv_sec and tv_nsec if only 100 million nanosecs are allowed? Docs for thrd_sleep and web resources don't mention .1 sec limitation.
TimoVJL:
In Windows 7
--- Code: ---#include <threads.h>
//#include <time.h>
#include <stdio.h>
int main(void)
{
printf("Time: %s", ctime(&(time_t){time(NULL)}));
thrd_sleep(&(struct timespec){.tv_sec=15}, NULL); // sleep x sec
printf("Time: %s", ctime(&(time_t){time(NULL)}));
return 0;
}
--- End code ---
--- Code: ---Time: Sun Dec 13 19:32:08 2020
Time: Sun Dec 13 19:32:23 2020
Press any key to continue...
--- End code ---
Stefan Pendl:
Output of Timo's code on Windows 10 with Pelles 10:
--- Code: ---Time: Sun Dec 13 20:07:33 2020
Time: Sun Dec 13 20:07:48 2020
Press any key to continue...
--- End code ---
John Z:
OK - you guys messing with me? :)
Here is what I get -
Time: Sun Dec 13 14:03:30 2020
Time: Sun Dec 13 14:03:30 2020
Press any key to continue...
Windows 10 - Pelles 9.00.9 although also on version 10 (which I'll retry - different computer)
I even used your posted code and pasted into a new project.... :'(
I have something corrupted?
I'll do the reboot but I do that every day :)
if you have a moment could you test this minor mod?
--- Code: ---#include <threads.h>
//#include <time.h>
#include <stdio.h>
int main(void)
{ int ans;
printf("Time: %s", ctime(&(time_t){time(NULL)}));
ans = thrd_sleep(&(struct timespec){.tv_sec=15}, NULL); // sleep x sec
if (ans < 0)
{ puts("error returned");}
printf("Time: %s", ctime(&(time_t){time(NULL)}));
return 0;
}
--- End code ---
I get an error with .tv_sec > .1 as in:
Time: Sun Dec 13 14:15:25 2020
error returned
Time: Sun Dec 13 14:15:25 2020
Press any key to continue...
Thanks for the help,
John Z
argggg - Worked fine on Windows 10 with Pelles 10.00.6 this time
Thank you all, need to see what is going on with this laptop ;( spent several hours trying to
figure out a code issue that's not a code issue......at least it is the weekend.
Stefan Pendl:
I created a 64-bit project, since I am running a 64-bit system.
Is there any difference, if the project is a 32-bit one?
Might be a problem with mixing 32-bit and 64-bit, system and application.
Navigation
[0] Message Index
[#] Next page
Go to full version