add sorting procedure when thread wants to add new message to queue