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()`.
Merge pull request #1961 from Kijewski/issue-1942

core: put more intelligence into `queue_msg()`