[fpc-pascal] Use sleep in thread

Henry Vermaak henry.vermaak at gmail.com
Wed Feb 25 16:18:40 CET 2015

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}
	sp: sched_param;
	sp.sched_priority := 10;
	{ SCHED_FIFO = 1 }
	pthread_setschedparam(ThreadID, 1, @sp);
	// TODO


More information about the fpc-pascal mailing list