core: protect against popping a message off the queue if no handler is attached.

This mostly solves a problem with threads being launched in random
order, so a handler might not be established yet, even if there is a
message waiting. Fixes Issue #514.