-
Notifications
You must be signed in to change notification settings - Fork 0
Architecture: Threading
localghost edited this page Jun 27, 2014
·
45 revisions
Information related to tasks can be found here.
There will probably be a couple of threads that would be accessed by different classes, e.g. thread through which all the libspotify API calls should be made.
- spotify_thread : all the libspotify API calls should be done through this thread
Possible solutions for adding tasks to a not running thread:
- Add a task so that it is executed whenever the thread is started
- Change the function's signature to return bool(false) and do not add task to the queue
- Assert when thread is not running (current approach)
- Throw exception if thread is not running
Currently, a thread can be stopped and re-started. However, the restart causes a new platform thread (std::thread
) to be created. This is a common approach AFAIK but if there are tasks left not executed before the thread is stopped then on a restart they will be run but on a different thread! Reconsider whether this is a valid approach - client developer might expect that if she put tasks on a specific thread then that's where they are gonna be executed.
Suggested solutions:
- clear the message loop on stop or before re-starting (add appropriate API in
base::message_loop
) - ...