Please note that non-unifying messages remain in the queue. After the
following has been executed, thread 1 has the term b(gnu)
in its queue and continues execution using A = gnat
.
<thread 1> thread_get_message(a(A)), <thread 2> thread_send_message(Thread_1, b(gnu)), thread_send_message(Thread_1, a(gnat)),
Term may contain attributed variables (see section 8), in which case only terms for which the constraints successfully execute are returned. Handle constraints applies for all predicates that extract terms from message queues. For example, we can get the even numbers from a queue using this code:
get_matching_messages(Queue, Pattern, [H|T]) :- copy_term(Pattern, H), thread_get_message(Queue, H, [timeout(0)]), !, get_matching_messages(Queue, Pattern, T). get_matching_messages(_, _, []). even_numbers(Q, List) :- freeze(Even, Even mod 2 =:= 0), get_matching_messages(Q, Even, List).
See also thread_peek_message/1.