Don't mix your processing, data and graphical display.
One solution is to have a common data structure which is shared between the two threads. The processing thread retrieves data from the store and dumps it back into the store. You might need a sleep or yield somewhere to stop it hogging the CPU.
The display thread just grabs data from the store and displays it. It doesn't do any processing at all. That way, the graphics is independent of the processing and you don't end up with big grey rectangles.