Hello Joel, thanks for the program, but it doesn't change the (mis-) behavior under RTEMS?
I add a 3 seconds delay (sleep 3).
clock_gettime( CLOCK_REALTIME, &now );
printf("\nnow tv_sec = %d, tv_nsec = %d\n", now.tv_sec, now.tv_nsec);
printf(" sleep 3 sec \n");
sleep(3);
clock_gettime( CLOCK_REALTIME, &now );
printf("\nnow tv_sec = %d, tv_nsec = %d\n", now.tv_sec, now.tv_nsec);
The issue is related to the clock_gettime()
it "sorts" the values incorrectly:
now tv_sec = 6683109, tv_nsec = 567993600
sleep 3 sec
now tv_sec = 10978989, tv_nsec = 567993603
on Unix:
now tv_sec = 1618027860, tv_nsec = 240887959
sleep 3 sec
now tv_sec = 1618027863, tv_nsec = 241181294
Heinz
> On 9. Apr 2021, at 20:19, Joel Sherrill <[email protected]> wrote:
>
> Hi
>
> I made some changes to test3.c so it can be compiled for RTEMS or
> any "normal" POSIX host like Linux. I avoided the rtems timespec
> addition method.
>
> I think this does what you expect on Linux but didn't try it on RTEMS.
>
> FWIW this is a good minimal example of how a program can support
> being built for Linux and RTEMS. For bigger examples, I prefer the RTEMS
> configuration and Init thread to be in a separate file. I think the psx
> reporting
> examples do that.
>
> --joel
>
> On Fri, Apr 9, 2021 at 12:45 PM Heinz Junkes <[email protected]> wrote:
> Jiri, Joel, thanks for your answers.
>
> @Joel: I was wondering that rtems-examples in psx_example_3 does not wait 3
> seconds.
>
> I made a curious observation:
>
> in the original code:
>
> clock_gettime( CLOCK_REALTIME, &timeout );
> timeout.tv_sec += 3;
> timeout.tv_nsec = 0;
> printf("The task is coming to enter in a timed wait\n");
> pthread_cond_timedwait(&cond, &mutex, &timeout);
>
>
> I then inserted some printfs and found that the "3" is added to the nsec’s.
>
> Then I added the rtems-timespec-helpers routines, but get the same behavior:
>
>
> void * print_hello(void * arg)
> {
> struct timespec now, timeout;
> rtems_timespec_set(&timeout, 3, 0);
>
> printf("<child>: Hello World! task with max priority \n");
> clock_gettime( CLOCK_REALTIME, &now );
> printf("now tv_sec = %d, tv_nsec = %d\n", now.tv_sec, now.tv_nsec);
> rtems_timespec_add_to(&timeout, &now);
> printf("timeout tv_sec = %d, tv_nsec = %d\n", timeout.tv_sec,
> timeout.tv_nsec);
> printf("The task is coming to enter in a timed wait\n");
> pthread_cond_timedwait(&cond, &mutex, &timeout);
> printf("The task is coming out from the timed wait \n");
> return NULL;
> }
>
> program output:
>
> <main> Enter in the main
> Creating first task
> <child>: Hello World! task with max priority
> now tv_sec = 4766459, tv_nsec = 567993600
> timeout tv_sec = 4766459, tv_nsec = 567993603
> The task is coming to enter in a timed wait
> The task is coming out from the timed wait
> First Task created
> Creating second task
> <child>: Hello World! Task with lowest priority Second task created
> <main> Out of the main
>
> If I now swap the arguments in the set-function , i.e. instead of
> rtems_timespec_set(&timeout, 3, 0);
>
> rtems_timespec_set(&timeout, 0, 3);
>
> it looks as it should
>
> <child>: Hello World! task with max priority
> now tv_sec = 10766729, tv_nsec = 567993600
> timeout tv_sec = 10766732, tv_nsec = 567993600
> The task is coming to enter in a timed wait
> The task is coming out from the timed wait
> First Task created
> Creating second task
> <child>: Hello World! Task with lowest priority Second task created
> <main> Out of the main
>
> But still no timed wait recognizable :-(
>
> Heinz
>
>
>
> _______________________________________________
> users mailing list
> [email protected]
> http://lists.rtems.org/mailman/listinfo/users
> <test3.c>
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________ users mailing list [email protected] http://lists.rtems.org/mailman/listinfo/users
