[Live-devel] Proper function calls from other threads (was: RE: All client termination)

Ross Finlayson finlayson at live555.com
Tue Sep 11 09:47:51 PDT 2012


> The code example below is called from an external thread. Is that ok

No - absolutely not!!!   What you're trying to do - call "TaskScheduler::scheduleDelayedTask()" from an external thread - is extremely wrong! 

Look folks, how many times do I have to say this: A LIVE555 application runs as a single-thread of control (using an event loop, rather than threads, to provide concurrency).  If you want to communicate with a LIVE555 application from an external thread (i.e., from a thread other than the one that runs the LIVE555 event loop), then there are only two proper ways to do this:
1/ By setting a global variable, or
2/ Using an 'event trigger' - i.e., by calling "TaskScheduler::triggerEvent()".  Note that "triggerEvent()" is the ***only*** LIVE555 function that you may call from an external thread.

This is all explained in the FAQ that you were all asked to read before posting to this mailing list!!!

In your case, you would do something like the following:
1/ Within the LIVE555 thread (e.g., somewhere after you've created "rtspClient"), call
	EventTriggerId myStopStreamEvent = env.taskScheduler().createEventTrigger(StopStream);
2/ Later, from an external thread, you can call:
	env.taskScheduler().triggerEvent(myStopStreamEvent, rtspClient);
and this will cause your "StopStream()" function to be called (with "rtspClient" as parameter) from the event loop - i.e., as a handled event.
(Note: For this to work, "env", "myStopStreamEvent" and "rtspClient" need to be global variables, so that they are visible to the external thread.  Note, though, that they are never *modified* by the external thread, only read by it.)


Ross Finlayson
Live Networks, Inc.
http://www.live555.com/

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.live555.com/pipermail/live-devel/attachments/20120911/b748bc59/attachment.html>


More information about the live-devel mailing list