|new_ctx||New context value.|
|old_ctx||Prior context value.|
The context functions provide a system-wide unique context and the means to manipulate this context.
Contexts provide the ability for communicating tasks to automatically differentiate messages by the context in which they were sent. Thus a message sent in context A by the sender must be received in context A by the recipient. A sender may send in any context. However, a recipient will not accept a message sent in a context that differs from its own.
One such use of contexts is with library routines. Using contexts, library routine inter-communication may be logically seperated from the users application inter-communication. This will prevent the inadvertent receipt of one anothers messages.
Spawned tasks inherit the spawn-time context of their parent. Existing PVM applications work unchanged using the default context.
pvm_newcontext returns a newly allocated context. However, this new context is not yet active.
pvm_setcontext changes the current context from old_ctx to new_ctx.
pvm_freecontext frees ctx so that it may be reused. Contexts are a system resource that will be exhausted if not recycled.
pvm_getcontext returns the current context of the requesting task.
/* parent task with context */ int cc, context0, context1; char buf;
context0 = pvm_getcontext(); /* get my current context */ context1 = pvm_newcontext(); /* get a new context */ pvm_setcontext(context1); /* set my context to new context */ printf("My context is: %d", context1); pvm_spawn("child", (char**)0, PvmTaskDefault, "", 1, &tid); cc = pvm_recv(-1, -1); /* receive message from child - in context1 */ pvm_upkstr(buf); printf("%s", buf); pvm_setcontext(context0); /* reset my context to my original context0 */
/* child task with context - child inherits parents context as default */ int context; int ptid; char buf;
ptid = pvm_parent(); context = pvm_getcontext(); /* get my current context */ sprintf(buf, "Greetings from child whos context is: %d.", context); pvm_initsend(PvmDataDefault); pvm_pkstr(buf); pvm_send(ptid, 1);
Only system resource errors will be returned as the context programs themselves do not generate errors.
|CONTEXT (3PVM)||8 April, 1997|