I'm currently working on redesigning an application which is building a model from input data, and displaying that data to the user. The current system has a thread for building the model, a thread for building a visualization of the model, and a thread which displays the visualization. The problem I have is that pointers are passed between the modeling and visualization threads - in order to make the threads safe, all objects in the model have to have a mutex. This means there are thousands of mutexes active in the system, with lots of stalls as both threads contend for resources.
So, given that those three threads will exist, what is the best way to share data between the modeling and visualization threads in a manner which is efficient and thread safe? Some of the data structures are large and will change every cycle of the modeling thread, so I'm somewhat loath to make a copy of the data every pass.
EDIT:
The total latency through the system we're hoping for is to have ~100ms from receiving a message to the display showing the change in the display. We would like it to be faster if possible, but more importantly we need it to be consistent - right now we see huge variability in the cycle times, due to the mutex contention. The data moving from modeling to visualization are dominated by 2D height maps - ~18000 cells worth of data. The actual number of cells updated in model update is significantly less though - perhaps only a few hundred.