copyrun that delivers exactly one run to the selected destination the heapsort programon the other handis complex routine relying on the availability of closed procedure select which simply selects new destination there would be no problemif in one (or bothof the programs the required procedure would be called at single place onlybut insteadthey are called at several places in both programs this situation is best reflected by the use of coroutine (thread)it is suitable in those cases in which several processes coexist the most typical representative is the combination of process that produces stream of information in distinct entities and process that consumes this stream this producer-consumer relationship can be expressed in terms of two coroutinesone of them may well be the main program itself the coroutine may be considered as process that contains one or more breakpoints if such breakpoint is encounteredthen control returns to the program that had activated the coroutine whenever the coroutine is called againexecution is resumed at that breakpoint in our examplewe might consider the polyphase sort as the main programcalling upon copyrunwhich is formulated as coroutine it consists of the main body of the program presented belowin which each call of switch now represents breakpoint the test for end of file would then have to be replaced systematically by test of whether or not the coroutine had reached its endpoint procedure distribute (srcfiles file)files file(adens _mergesorts *const mh div (*heap size*var lrintegerxintegerdestfiles filerwfiles riderharray of integer(*heap*procedure sift (lrinteger)var ijxintegerbegin :lj : * + : [ ]if ( [ + ]then inc(jendwhile ( [ ]do [ : [ ] :jj : * + if ( [ + ]then inc(jend endh[ : end siftbegin files set(rsrc )dest :files new("")files set(wdest )(*step fill upper half of heap* :mrepeat dec( )files readint(rh[ ]until mh(*step fill lower half of heap*repeat dec( )files readint(rh[ ])sift(lm- until (*step pass elements through heap* :mfiles readint(rx)while ~ eof do files writeint(wh[ ])if [ < then (* belongs to same run* [ :xsift( - else (*start next run*