<div dir="ltr">Hi<div><br></div><div>I  made some changes to test3.c so it can be compiled for RTEMS or</div><div>any "normal" POSIX host like Linux. I avoided the rtems timespec</div><div>addition method.</div><div><br></div><div>I think this does what you expect on Linux but didn't try it on RTEMS.</div><div><br></div><div>FWIW this is a good minimal example of how a program can support</div><div>being built for Linux and RTEMS. For bigger examples, I prefer the RTEMS</div><div>configuration and Init thread to be in a separate file. I think the psx reporting</div><div>examples do that.</div><div><br></div><div>--joel</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Apr 9, 2021 at 12:45 PM Heinz Junkes <<a href="mailto:junkes@fhi-berlin.mpg.de">junkes@fhi-berlin.mpg.de</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Jiri, Joel, thanks for your answers.<br>
<br>
@Joel: I was wondering that rtems-examples in psx_example_3 does not wait 3 seconds.<br>
<br>
I made a curious observation:<br>
<br>
in the original code:<br>
<br>
   clock_gettime( CLOCK_REALTIME, &timeout );<br>
   timeout.tv_sec += 3;<br>
   timeout.tv_nsec = 0;<br>
   printf("The task is coming to enter in a timed wait\n");<br>
   pthread_cond_timedwait(&cond, &mutex, &timeout);<br>
<br>
<br>
I then inserted some printfs and found that the "3" is added to the nsec’s.<br>
<br>
Then I added the rtems-timespec-helpers routines, but get the same behavior:<br>
<br>
<br>
void * print_hello(void * arg)<br>
{<br>
  struct timespec now, timeout;<br>
  rtems_timespec_set(&timeout, 3, 0);<br>
<br>
  printf("<child>: Hello World! task with max priority \n");<br>
  clock_gettime( CLOCK_REALTIME, &now );<br>
printf("now tv_sec = %d, tv_nsec = %d\n", now.tv_sec, now.tv_nsec);<br>
  rtems_timespec_add_to(&timeout, &now);<br>
printf("timeout tv_sec = %d, tv_nsec = %d\n", timeout.tv_sec, timeout.tv_nsec);<br>
  printf("The task is coming to enter in a timed wait\n");<br>
  pthread_cond_timedwait(&cond, &mutex, &timeout);<br>
  printf("The task is coming out from the timed wait \n");<br>
  return NULL;<br>
}<br>
<br>
program output:<br>
<br>
<main> Enter in the main<br>
Creating first task<br>
<child>: Hello World! task with max priority<br>
now tv_sec = 4766459, tv_nsec = 567993600<br>
timeout tv_sec = 4766459, tv_nsec = 567993603<br>
The task is coming to enter in a timed wait<br>
The task is coming out from the timed wait<br>
First Task created<br>
Creating second task<br>
 <child>: Hello World! Task with lowest priority Second task created<br>
<main> Out of the main<br>
<br>
If I now swap the arguments in the set-function , i.e. instead of<br>
 rtems_timespec_set(&timeout, 3, 0);<br>
<br>
 rtems_timespec_set(&timeout, 0, 3);<br>
<br>
it looks as it should<br>
<br>
<child>: Hello World! task with max priority<br>
now tv_sec = 10766729, tv_nsec = 567993600<br>
timeout tv_sec = 10766732, tv_nsec = 567993600<br>
The task is coming to enter in a timed wait<br>
The task is coming out from the timed wait<br>
First Task created<br>
Creating second task<br>
 <child>: Hello World! Task with lowest priority Second task created<br>
<main> Out of the main<br>
<br>
But still no timed wait  recognizable :-(<br>
<br>
Heinz<br>
<br>
<br>
<br>
_______________________________________________<br>
users mailing list<br>
<a href="mailto:users@rtems.org" target="_blank">users@rtems.org</a><br>
<a href="http://lists.rtems.org/mailman/listinfo/users" rel="noreferrer" target="_blank">http://lists.rtems.org/mailman/listinfo/users</a></blockquote></div>