Monday, April 11, 2016

Day 93: Deadlock

Phew! Today was a tough coming back with a homework assignment that I didn't know was still going to be assigned.

Looks like asynchronous event handling was still on the schedule, though. I've already had experience with asynchronous programming with std::async and futures, but actually coming up with a solution for testing certain conditions was tougher than ever, mainly due to the fact that I'm not sure what the professor considers an applicable solution.

I decided to just go with a timeout on the event to stop thread deadlock and/or starvation. The idea is to do a try_lock_for, then continue onward with optional completion. I first went with timed_mutex objects, but a lock_guard was recommended, or an object that treats mutex locking/unlocking like a shared_ptr handles memory allocation and deletion. THEN I had to handle multiple locks of the same thread, as usual timed_mutex objects would not allow it.

The key? recursive_timed_mutex objects! They're actually a thing.

That mainly took up my time for today, but I think I get back to working on other more important things.

No comments:

Post a Comment