Is there some way to execute a code section while waiting for a mutex to lock?
The only true internal hit to my application's performance is database interaction, and there are times where I need strict synchronization which because of the database interaction may cause contention, so I'd like to use the time waiting for a lock to get data from the database.
For example, I'd like the code to look something like, in pseudo:
boost::unique_lock<boost::mutex> process_lock(process_mutex, work_while_contending);
//code to execute while lock contending
process_lock.proceed_after_lock();
I've examined boost's synchronization section, and while futures
and recursive
sound like my intent could be achieved, but I can't figure out how to implement my intent.
How can my intent be implemented?