Menu

#345 Blocked indefinitely in the nanosleep() call

2.1.0.0
closed
None
2021-08-11
2020-10-08
Gari
No

Only when using multithreading (as of in High Performance Mode) nanosleep() at vos_threadDelay() can all the time get interrupted and thus leaving the program stuck in an unexpected infinite loop.

This problem occurs in an environment with many interruptions. If an interruption ocurrs during the call of nanosleep(), in theory the nanosleep() function is called again with the updated time (the original time minus the time expired in the previous call) but what happens is that it remains blocked indefinitely.

Taking a look at the man page of the nanosleep function, in relation to this problem it says the following: "The fact that nanosleep() sleeps for a relative interval can be problematic if the call is repeatedly restarted after being interrupted by signals, since the time between the interruptions and restarts of the call will lead to drift in the time when the sleep finally completes. This problem can be avoided by using clock_nanosleep(2) with an absolute time value."

In conclusion, replacing the nanosleep () function with clock_nanosleep () fixes the problem.

I attach the file "src/vos/posix/vos_thread.c" (versión 2.0.2.0 of the trdp library) with the solution.

1 Attachments

Discussion

  • Gari

    Gari - 2020-10-08

    The original file (src/vos/posix/vos_thread.c)

     
  • Armin-Hagen Weiss

    • Milestone: 2.0.2.0 --> 2.1.0.0
     
  • Bernd Löhr

    Bernd Löhr - 2020-11-03
    • status: open --> accepted
    • assigned_to: Bernd Löhr
     
  • Bernd Löhr

    Bernd Löhr - 2020-11-03

    Hi Gari,
    thanx a lot. I'll incorporate your changes asap.
    /Bernd

     
  • Bernd Löhr

    Bernd Löhr - 2020-11-03
    • status: accepted --> pending
     
  • Bernd Löhr

    Bernd Löhr - 2020-11-03

    @Gari: Can you verify the current implementation (trunk)?

     
  • Gari

    Gari - 2020-11-04

    @bloehr: We try to integrate the trunk implementation in our code to check it but we get some compilation errors related to the differences between both codes and we can´t verify it. However, the patch has been applied just as we reported, so it looks like it will work fine.

     
    • Bernd Löhr

      Bernd Löhr - 2020-11-04

      This most probably because of some minor API changes in 2.1 because of the conformance testing.
      Which OS is your target: Linux or Integrity?

       
  • Gari

    Gari - 2020-11-04

    Hi Bernd!
    @bloehr: It's Linux.

     
  • Iris Bosse

    Iris Bosse - 2021-08-11
    • status: pending --> closed
     
  • Iris Bosse

    Iris Bosse - 2021-08-11

    changed, tested by inspection

     

Log in to post a comment.

MongoDB Logo MongoDB