2 ms·
Yes. Either use threadsafe queues/ringbuffers to transfer data between threads. Or triple-buffer it and swap buffers in a threadsafe manner. Those are the best
by Kenji 9y ago
Yes. Either use threadsafe queues/ringbuffers to transfer data between threads. Or triple-buffer it and swap buffers in a threadsafe manner. Those are the best approaches.
Don't start a thread per work item. Start worker threads and distribute work among them. Never ever block a GUI thread.
Always know which thread works on which data structures and don't even make more variables accessible in your worker threads. Keep the variables multiple threads can access to an absolute minimum and make sure access is always protected by a mutex.
If you repect these rules, threading is safe and fun.