Posix Threading advice for high rate thread interferance


I'm looking for the best way to set up a problematic architecture. So far, I have not had success and a variety of failure modes.

I have 3 threads (4 if you count the main loop which watches for a Ctrl-C), 2 of which are slower, 1 of which is very fast. The fast thread reads data from an IMU and must stay at a high rate. The processing thread shares a global array with the IMU thread. It copies over the data in the global array to a local array and does processing on that. The data is then sent over to a communication thread.

My issue is that, I have given the IMU thread highest priority (for a non-root process). How do I work it so that the IMU thread can maintain a high rate but the other threads can still run. If I use a mutex lock in the IMU thread, it never lets it go and the other threads do not run. (and I can't ctrl-c to end the program)

The high priority also does not let the other threads run. If I make all the priorities equal, the IMU thread does not run fast enough and all the data is garbled. (as in, if I don't match speeds with the IMU the values coming out of the IMU are modified- 0xFF becomes 0xee or whatever)

I am unsure how to do this such that I can both have the high rate thread, grab data from that thread when needed, and have the rest of threads running.

Help would be much much appreciated. Thanks in advance.
In my experience, increasing the priority of a thread doesn't increase it's performance. Instead, it just seems to slow everything else down. I found it best to never tinker with thread priorities. The OS knows best.

You need to queue the results with minimal locking.

In my experience, performance matters are solved in iterations. You solve the big problem and if you're not fast enough, you look for the next big problem and solve that.
Topic archived. No new replies allowed.