The Concurrent ML Reference Manual


The Mailbox structure


Synopsis

signature  MAILBOX
structure Mailbox : MAILBOX

The Mailbox structure provides buffered asynchronous channels, which we call mailboxes.


Interface

type 'a mbox
val mailbox : unit -> 'a mbox
val sameMailbox : 'a mbox * 'a mbox -> bool
val send : 'a mbox * 'a -> unit
val recv : 'a mbox -> 'a
val recvEvt : 'a mbox -> 'a event
val recvPoll : 'a mbox -> 'a option

Description

type 'a mbox
This is the type constructor for a mailbox. A mailbox is an unbounded, buffered communication channel.

mailbox ()
creates a new mailbox.

sameMailbox (mb1, mb2)
returns true, if mb1 and mb2 are the same mailbox.

send (mb, msg)
sends the message msg to the mailbox mb. Note that unlike CML.send, this is a non-blocking operation.

recv mb
receive the next message from the mailbox mb. If, the mailbox is empty, then this blocks the calling thread until there is a message available.

recvEvt mb
returns the event value that represents the recv operation on mb.

val recvPoll : 'a mbox -> 'a option
This is the non-blocking version of recv. If the corresponding blocking form would block (because the mailbox is empty), then this returns NONE, otherwise it returns SOME of the received message.

See Also

CML

Discussion

Note that mailbox buffers are unbounded, which means that there is no flow control to prevent a producer from greatly outstriping a consumer, and thus exhausting memory. In situations where there is no natural limit to the rate of send operations, it is recommended that the synchronous channels from the CML structure be used instead.


[ Top | Parent | Contents | Index | Root ]

Last Modified &date;
Comments to John Reppy.
Copyright © 1991-2003 John Reppy