Compiler optimization messing synchronization
Posted: Sun Apr 03, 2011 9:29 pm
Hi,
While stepping through the code debugging something else I realized with shock that the compiler had rearranged the instructions in an order that would mess up the thread synchronization big time (changed writing to buffer and signaling a semaphore into the ...opposite ordering). I went searching and turns out this is not an unusual complaint working with multithreaded apps.
Is the ChibiOS code somewhat safe from this?? What can I do to avoid this happening when compiling the RTOS? (other than turning off optimization, but it may have to come to that)
Ian
While stepping through the code debugging something else I realized with shock that the compiler had rearranged the instructions in an order that would mess up the thread synchronization big time (changed writing to buffer and signaling a semaphore into the ...opposite ordering). I went searching and turns out this is not an unusual complaint working with multithreaded apps.
Is the ChibiOS code somewhat safe from this?? What can I do to avoid this happening when compiling the RTOS? (other than turning off optimization, but it may have to come to that)
Ian