« Return to Thread: 'not' as atomic symbol

Re: message queue put-back and backtracking

by Jan Wielemaker :: Rate this Message:

Reply to Author | View in Thread

Samer,

On Friday 12 January 2007 15:26, Samer Abdallah wrote:
> Would it be much trouble to add a
> thread_putback_message(Queue,Term) procedure
> which pushes Term onto the head of the queue?
> Even better would be a backtrackable version of
> thread_get_message/2 which pushes back the term it just
> read on backtracking. (If this seems like an odd request,
> I can explain what I'm trying to do - just thought I'd
> keep my initial post short and to-the-point.)

The analogy for message queus is more like a reading/writing to a pipe,
containing terms rather than characters. I'm not saying this can't be
done, but given the possibility of access from multiple threads, strange
things can happen.

Another disadvantage is that it makes thread_get_message
non-deterministic.  Somewhat more in line with the desing might be
a thread_send_message that puts the new message at the head rather
than at the tail.  That allows for a design like:

        ndet_get_message(Queue, Message) :-
                thread_get_message(Queue, Message),
                (   true
                ;   thread_send_message(Queue, Message, [at(head)]),
                    fail
                ).

Note however that this implementation is not correct with respect to the
cut.

So, I'd prefer to consider the problem at a somewhat higher level first
to see whether there is an elegant solution you missed there.

        Cheers --- Jan


------------
For further info, please visit http://www.swi-prolog.org/

To unsubscribe, send a plaintext mail with "unsubscribe prolog <e-mail>"
in its body to majordomo@...

 « Return to Thread: 'not' as atomic symbol

LightInTheBox - Buy quality products at wholesale price