core: put more intelligence into `queue_msg()`

Fixes #1942.

There were two instances were it was not checked the target thread has a
message queue before queuing the message.

This PR centralizes the check into `queue_msg()`.

(This PR is part of #1939)