24: Sponsored Operations and Multitasking
- Sponsored Operations
- When a process calls an unsponsored operation (which all ops are unless declared otherwise) on an object, the process (the requester) is the sponsor of that operation.
- The operation runs under the authority and permit of its sponsor so it won't use resources and perform actions that are beyond permissions for the sponsor.
- When one process calls an operation on a second process, the requester (first process) is by default the sponsor, so the operation runs under the authority and permit of the first process, even though it belongs to the second process, which has its own authority and permit.
- A process may want some of its operations to run under its own authority and permits even when called by other processes. If so, it declares those operations to be sponsored operations. (Think of them as "self-sponsored" operations.)
- An operation is declared to be a sponsored operation using the "sponsored" keyword
- Operations so declared execute under the authority and permits of their responder, not under the authority and permits of the requester with one exception:
- The age capability is the most constrictive setting found in the responder's permits and the requester's permits. This ensures that a sponsored operation must take no longer than the time available to the requester or the responder.
- Operations not declared using this keyword execute under the authority and permits of the requester.
- Some operations in a process must be declared sponsored operations because they're called by the engine, and must execute under the authority and permit of the process and not of the engine. Those operations are:
- "live", called when a process is first constructed
- "entering", called when a process first enters a place (on construction or later)
- "meeting", called when an agent is requested for a meeting
- Operations that are not part of a process may not be declared a sponsored operation, because the object has no authority or permit.
- The engine starts a thread each time it calls a sponsored operation on a process.
- A thread is a stream of execution; many threads can execute simultaneously in the multitasking environment of the Telescript engine.
- A process may have more than one thread executing at once, so it can, in theory, be simultaneously living (one thread) and performing sponsored operations for other processes (a thread for each operation).
- A thread is a FILO stack of frames.
- Each frame supports a single method.
- A frame contains the variables and a stack of arguments used in the method.
- A frame is added to the thread each time an operation is called (unless, of course, the operation is a sponsored operation called by the engine).
- A frame is popped from the thread each time an operation is finished.
- Only the frame at the top of the thread is executed. Its method is called the current method. The current method works with the variables and arguments in the frame.
- When an operation is finished, its thread is destroyed.
- The engine can support concurrent threads through multitasking so each thread executes independently of another.
- Priority
- Each process has a permit-granted priority of -20 (low) to 20 (high). (0 is the normal priority.) A process's threads run at that priority.
- The engine spends equal execution time on threads of equal threads of the highest priority (unless a process is blocked, in which case its thread doesn't execute).
- Lower-priority threads must wait until higher-priority threads finish execution; the lower-priority threads then take their turn as the highest-priority threads--until a higher-priority thread appears, at which point they're suspended once again.
TS Ref - 26 JUN 1996
Generated by the sweat of Mike Boom's brow.