Menu

read sync bug

Help
2008-10-03
2013-04-23
  • Ray Wilhelm

    Ray Wilhelm - 2008-10-03

    In tracking down program crashes, I think I might have found a bug in the libserial read code.

    From what I can tell, serial port reads happen through a signal handler function which fills a stl queue with data.  The SerialPort::Read() functions then pull data from that stl queue.

    The stl queue that passes information between the SignalHandler and the SerialPort::Read() functions has no protections (e.g. mutex) to prevent simultaneous access to the stl queue.

    Since the SIGIO signal can interrupt the user's thread at anytime, this can cause problems if you are lucky enough to have the folllowing happen:

    1. User Calls SerialPort::ReadByte()
    2. In the middle of executing the mInputBuffer.pop() function call
              the SIGIO signal is raised and the SerialPort::HandlePosixSignal() gets immediately called
    3. In the  SerialPort::HandlePosixSignal() function, the mInputBuffer.push() function is called
    4. Execution returns back to SerialPort::ReadByte(), and the mInputBuffer.pop() finishes
    5. Now the stl queue is corrupted and the random crashes start.....

    Please let me know if anybody can confirm/deny that this is a problem.  This is my first time looking at the internals of libSerial, but thus far I am fairly sure the above described problem is the smoking gun in my case.

     
    • Crayzee Wulf

      Crayzee Wulf - 2008-10-03

      Ray:

      Thanks for reporting this bug and also for your excellent explanation of the problem. I think this is a genuine bug that needs to be fixed. I will review the code you mentioned to see if I can come up with a clean solution.
      --
      Crayzee Wulf

       
    • Crayzee Wulf

      Crayzee Wulf - 2008-10-03

      I have created a bug report for this message. Please use this bug report for all future discussion.

      https://sourceforge.net/tracker/?func=detail&atid=109432&aid=2145278&group_id=9432

       

Log in to post a comment.