Original Post
Here's the rundown. I'm wondering if there is a better way to do this: Pseudo flow for my C++ code: The idea behind it being that Thread A is doing a lot of things, and doesn't care when "Request" gets done, just that someday it might get done. Thread Z just processes requests as they come in, doing partial work on each item in the priority queue till they are done. Is it safe to just "synchronize" this with a standard bool as a flag "i'm done!" or is there a better way to "callback" to thread A that it can work with the data now? background for those who care: Thread A-Y are threads that might need data. Thread Z, prioritizes asynchronous file reads from the disk in an attempt to maintain datarate and deadline times for different requests. For example, the system may want to load a 200Mb data file, but there is a movie playing now that has a hard datarate requirement inorder to not stutter. On a normal read call the OS doesn't know how important the data is, so the movie may suffer instead of the data just waiting to finish till the movie is over. Edit: Hell, couldn't I even just wait on the status to change to something valid, and proceede from there? I guess my big fear is that without the synchronization primitive, the CPU A may never get an updated copy of the memory edited by Thread Z for that flag. [Edited by - KulSeran on March 18, 2009 12:44:32 AM]
[L] - Lock
- Unlock
Thread A:
volitile bool _request_done = false;
[L] Add Request ( data, &_request_done )
while ( 1 )
do things
if ( _request_done ) [L] Pop Request and final status process outputs
Thread Z:
[L] Find Request
Process Request
[L] Update Status
if ( status == DONE ) (*request._callbackFlag) = true;