I just need to avoid calling such functions between a stream, here is the idea, so I would do to safely exchange a lot of data.
and you should have a state machine with both threads, access to the shared variable to be locked (use pointer for the main thread, which points to the ping or pong buffer + mutex for your lock)
so you can change the way data is used, the βdisplayβ should always use the same pointer. It should get a lock at the start of reading and letting go after.
The camera should write in another buffer. After the camera fails, the camera thread should try to set a lock for the mutex, and if it acquires it (that is, another stream does not read another buffer), then the camera stream should take a lock and change the buffer. pointed to by the pointer used by the main thread)
This way you have no connection between threads, just a mutual exception.
The biggest risk is to never get the lock from the camera thread, here is the solution β To limit the lock time, I advise you to have a second buffer in each thread, so the lock time will be reduced to the duration of "memcpy". Add a bool to the structure, this says if your camera updated the data or not.
If so, the main stream copies the data. (and the camera cannot change pointers at this time), but as soon as this is done, the main thread also reset bool to false. And until this bool returns to the truth, you do not need to block copying data. (now this is a lock-free exchange) Note that this is only true because reading bool is an atomic action.
I hope this helps
(sorry for my English)
dzada source share