task messaging
- Posted by useless Sep 12, 2009
- 1010 views
I believe i have task messaging done for task.e.
There's two message types var and queue.
Var is a single var that is overwritten on each send, it's useful for rapidly changing data that is written often and only the last write is valid. Also useful for a situation where a flag is set in a loop in another task, and you don't feel like testing for it already been sent (tho this eats cpu time).
Queue is accumulative. Writes to it are not overwritten, but stay in the queue until read. Msgs are stored in the order recieved, there's no prioritising system (till it's requested, along with a suggested implementation). These are useful for data that should be read by the task it's sent to. Each read deletes one queued msg. There is no command to read all msgs from one task.
Commonalty of both-
Anything you can put into an Eu object type can be a msg.
Both var and queue outlive the task that wrote them and the task that they are sent to. In this way, a task can end now, and it's (normally returned) msg read later. The msg can now be sent to any or all other tasks, not just returned to the parent process. Rather than memory filling up with msgs to dead tasks, any task can read them, and thereby clear them.
Both are used by specifying the source and the target task id atom. Only one source task id can be used (altho it is not required to be the real task_self()), but groups of target ids or from ids can be used like {1,2,6,9}.
Both accept "*" to read from all senders or send to all tasks. This broadcast mode does not read from or write to the sender's var or queue. It will return all non-empty vars, and the next non-empty queued msg. All "*" or multiple reads will return the form {{senderid,"foo"}} , even if only one msg is returned.
Specifically reading from or writing to the sender's var or queue is allowed.
Both return the sender id when multiple reads are requested.
Both return the following formats- "foo"
single read-
multiple reads- {{senderid,"foo"},{senderid,"boo"}}
Requests for the code for evaluation and suggestions will be entertained.
[edited:Derek -> Now shows how to enter double braces {{}} as non=markup.]
useless