On Wed, Feb 25, 2015 at 10:41:58PM +0800, Xiangrong Fang wrote:
> Hi All,
> 
> Can I use Sleep() in a thread to give up cpu time to other threads running
> at the same time, so as to adjust the relative "niceness" of a group of
> workers working on the same subject (in which each thread take part of the
> whole task).

Use ThreadSwitch to yield CPU.  Having said that, it may be better to
look into platform specific thread scheduling rather than trying to do
it yourself.  For instance, with pthreads, you can do this:

procedure TYourThread.SetPriority;
{$ifdef unix}
var
        sp: sched_param;
begin
        sp.sched_priority := 10;
        { SCHED_FIFO = 1 }
        pthread_setschedparam(ThreadID, 1, @sp);
end;
{$else}
begin
        // TODO
end;
{$endif}

Henry
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to