CONTEXT(3PVM)

πŸ“¦ version 3.4.6, in debian bookworm, ubuntu jammy

πŸ‘‘ CONTEXT β€” the PVM context girlies πŸ’…

ok so this is CONTEXT(3PVM) from PVM Version 3.4, and it's literally the whole context situation. Four little functions, one big vibe: pvm_newcontext, pvm_setcontext, pvm_freecontext, and pvm_getcontext. Their whole job? Request a new context, change your context, free an existing context, and get your current context. Respectively, bestie. πŸŽ€


✨ SYNOPSIS ✨

C, my beloved:

int ctx = pvm_newcontext( void )
int old_ctx = pvm_setcontext( int new_ctx )
int info = pvm_freecontext( ctx )
int ctx = pvm_getcontext( void )

Fortran said "hold my 🫢":

call pvmfnewcontext( ctx )
call pvmfsetcontext( new_ctx, old_ctx )
call pvmffreecontext( ctx, info )
call pvmfgetcontext( ctx )

🌸 PARAMETERS 🌸

  • ctx β€” a context value. just a lil guy. a number that means something.
  • new_ctx β€” the new context value. the one you're switching to. main character energy incoming.
  • old_ctx β€” the prior context value. the one you're leaving behind, no hard feelings.
  • info β€” result code. it tells you how it went. πŸ’€ or 😌, depends.

πŸ’– DESCRIPTION πŸ’–

The context functions hand you a system-wide unique context plus the tools to mess with it. That's the whole point.

So here's the tea: contexts let communicating tasks automatically tell messages apart based on the context they were sent in. Which means β€” and this is the rule, no cap β€” a message sent in context A by the sender must be received in context A by the recipient. A sender can send in any context it wants. But a recipient will not accept a message sent in a context that differs from its own. hard pass, blocked, do not perceive me. πŸ™ˆ

One classic use is library routines. With contexts, a library routine's inter-communication can be logically separated from your application's inter-communication. Which prevents everyone from accidentally receiving each other's messages like it's a group chat with no mute button. 😭

Spawned tasks inherit the spawn-time context of their parent. And existing PVM applications keep working totally unchanged using the default context. no migration era, we love that for them. ✨

Now the four functions, one by one:

  • pvm_newcontext returns a newly allocated context. But β€” plot twist β€” this new context is not yet active. it's allocated, it's not live. don't @ me.
  • pvm_setcontext changes the current context from old_ctx to new_ctx. glowed up, moved on. πŸ’…
  • pvm_freecontext frees ctx so that it may be reused. and listen β€” contexts are a system resource that will be exhausted if not recycled. so like, recycle. please. it's giving finite.
  • pvm_getcontext returns the current context of the requesting task. just asks "who am i rn" and gets an honest answer. πŸ¦‹

🧚 EXAMPLES 🧚

parent task with context β€” the parent sets the vibe, spawns a child, and gets a lil greeting back:

/* parent task with context */
     int cc, context0, context1;
     char buf[25];

     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 parent's context as default, then says hi very politely:

/* child task with context - child inherits parent's context as default */
     int context;
     int ptid;
     char buf[25];

     ptid = pvm_parent();
     context = pvm_getcontext();        /*  get my current context */
     sprintf(buf, "Greetings from child who's context is: %d.", context);
     pvm_initsend(PvmDataDefault);
     pvm_pkstr(buf);
     pvm_send(ptid, 1);

😭 ERRORS 😭

ok so this is genuinely chill: only system resource errors will be returned, because the context programs themselves do not generate errors. they're not dramatic. they're not messy. they simply do not start anything. periodt. ✨


πŸ‘€ SEE ALSO πŸ‘€

ngl bestie, the original page lists literally nothing here β€” it just rolls straight into the footer. no cross-references, no extra reading, just vibes. 🌈


reminder for the girlies: if you don't recycle your contexts with pvm_freecontext, you will run out, because contexts are a system resource. that's not a vibe, that's a warning. πŸ’€

that's the page, babe 🫢 β€” from PVM Version 3.4, dated 8 April, 1997. yes it's old, no we don't care, it ate. πŸ’œ

πŸ“¦ where this page comes from