Samstag, 16. Februar 2008

the joys of multi-threading

Finally found the error that caused the random segmentation fault in my control-server - lesson learned: be careful what you pass to a thread as argument, if it might be freed prematurely.

Nothing I didn't know before, but because I removde the semaphore-based inter-locking of my main-thread with the control-loop - because semaphores require RTAI to be active, which caused the preemption-troubles of the past - perfectly working code became a subject of a race-condition: how's faster - the control-thread in fetching the data out of the passed argument, or the main-thread in releasing the argument because it's stackframe gets removed... depending on the winner, things work smoothly or segfault.

Beside that I made the index-bit-stuff work, which suxors, btw - I don't get the current index-bit-state, but instead the bit is latched once and must be reset. Thus I can only gather the index-position on a rising edge, which makes measuring the index-gap only possible with reverting the direction. Something that will cause imprecisions in the gears to become part of the picture... sigh