Logo

Programming-Idioms

Explicitly decrease the priority of the current process, so that other execution threads have a better chance to execute now. Then resume normal execution and call the function busywork.
Implementation
Pascal

Implementation edit is for fixing errors and enhancing with metadata. Please do not replace the code below with a different implementation.

Instead of changing the code of the snippet, consider creating another Pascal implementation.

Be concise.

Be useful.

All contributions dictatorially edited by webmasters to match personal tastes.

Please do not paste any copyright violating material.

Please try to avoid dependencies to third-party libraries and frameworks.

Other implementations
import "runtime"
runtime.Gosched()
busywork()
Thread.yield();
busywork();
::std::thread::yield_now();
busywork();
System.Threading
Thread.Yield();
busywork();
use Coro;
sub busywork { print 'busy' };

my $n = 12;

my $th_sub = sub {
    my ($limit) = @_;
    foreach ( 1 .. $limit ) {
       print '.';
       cede;
    }
};

my $th = Coro->new( $th_sub, $n );

$th->ready;

foreach my $ii ( 1 .. $n ) {
    if ( $ii == int $n * 2/3 ) {
        $Coro::current->prio(-1);
        cede;
        busywork();
    }
    print '-';
    cede;
}