Tom Ramcigam (magicmarmot) wrote,
Tom Ramcigam

Sometimes I hate C code.

I currently have two circular buffers, one for each COM port.

I have a parent thread and an "interrupt" thread. Currently I just have the interrupt thread set on a timer so that it runs periodically. This bypasses the whole normal interrupt processing and moves everything to a polling routine.

Everything is fine, except that both threads are attempting to access the circular buffer. When I receive a character in the serial port, it's supposed to grab it from the chip's buffer and push it into the circular buffer. This then increments the head pointer.
It then tests to see if the head pointer has run back into the tail pointer, which would mean a buffer-full error is happening.

The problem is that the parent thread is reading the character out before the test, and bumping the tail pointer. This makes it look like the buffer is full when it's not, so I lose my characters in the receive buffer.

To solve this, I'd like to use a semaphore so I can mutex the circular buffer operations. The problem is that the parent thread doesn't know anything about semaphores.


  • Fox News science beat

    Scientists Not So Sure 'Doomsday Machine' Won't Destroy World Still worried that the Large Hadron Collider will create a black hole that will…

  • (no subject)

    I've been having real problems sleeping. My sleep schedule has kind of fragmented into a wild series of unscheduled naps with no real pattern.…

  • (no subject)

    Confessions of even the most heinous of crimes and sins — such as genocide or mass murder — are handled at the local level by priests and their…

  • Post a new comment


    default userpic

    Your reply will be screened

    Your IP address will be recorded 

    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.