I have been trying to learn POSIX threads
programming for my Gumstix application - to receive data from an 16-bit ADC via
SPI and store the samples to a log file, with both processes running in
I've succeed in trying to make the two processes running simultaneously using pthread in C. I've used a binning approach to store the data i.e. to transfer the read data buffer to the write data thread whenever the sample bin is full. However, I've got a problem after I saw the results from the log file - there is a time delay between reading the samples and writing the data to the file. I'm using the fwrite command for the writing (which should be acceptable in speed). I've also tried using the memcpy command to transfer the read data buffer to a new data buffer for writing, but it could not resolve the delay problem. I've implemented the flags to "communicate" between the read and write threads.
I’m willing to send the C program to anyone who is interested to have a look at it. I'll greatly appreciate if anyone can enlighten me on what are the possible mistakes I could have made and if there is a better/smarter way of dealing with multithreading (if not using pthread).
Can I ask if anyone has tried using multithreading for their application and are willing to share with me their experience? Any comments from robotic enthusiasts will be valued, as I believe this is a common issue where one tries to receive and process the sensor data. I'm dealing with the ADC which can receive/store the data at sampling rate of 7kHz.