I use a library (WebRTC), that fire all event in one of its own and opaque background thread. So this is the flow I m facing :
:: MainUIThread
fMyWeRTC.doSomeThink;
:: WebRTC own and opaque background Thread
Procedure fMyWebRTC.renderFrame(frame: TRTCFrame);
begin
TThread.synchronize(nil,
procedure
begin
... Draw the frame .... // I can render only in main UI thread
end;
end;
The problem is that when you call fMyWeRTC.doSomeThink;
, the library internally call renderFrame in it's own background thread and wait its return (crazy but it's made like this, I can't change it). So here I enter in a deadlock :(
What are my option ?
- Use
queue
instead ofsynchronize
? no possible because frame is alive only for the time of renderFrame. I don't also want to spend extra memory and time to duplicate it in memory. - Do
fMyWeRTC.doSomeThink
in a background thread (with for exampleTAnonymousThread.execute
)? that is quite opaque too, the doc doesn't say if we can call any functions from a background thread (when I tried, I have sometimes some exception). To stay on the safe way I prefer to call everything from the main UI thread
So how you can handle this situation?
See Question&Answers more detail:os