::SHE+ILA:: Coroutines

Elegant women in violet dresses at a lavish table
124
0
  • Squishy Plushie's avatar Artist
    Squishy Pl...
  • Prompt
    Read prompt
  • DDG Model
    DaVinci2
  • Access
    Public
  • Created
    2d ago
  • Try

More about ::SHE+ILA:: Coroutines

Consider the two functions :
Foo <:: {* msj << i++; {? ?msj ?}; msj << j++; {? ?msj ?}; *};
and Bar <:: {* {? msj? ?}; msj =>> x; ttyout x; *};
Foo alternately increments i and j, and sends it as a message to Bar, and Bar waits for a message and prints it. Foo has two independent sequential phases : increment i, wait for Bar to receive the message, increment j, wait for Bar to receive the message; then loop back and do it again. Bar repeatedly waits for a message and then prints it. Typically these two functions would run concurrently, on separate threads thus :
{! Foo; Bar !};
{? ?msj ?} waits for msj to become empty, and {? msj? ?} waits for msj to become full. These acheives a coroutine rendezvous mechanism, sometimes known as a "producer/consumer pair".

Comments


Loading Dream Comments...

Discover more dreams from this artist