[SOLVED] Real Time Threading under Linux (Debian) lazarus / 32-Linux ---------------------------------------------------------------------- Greg · 2013-02-18 10:14 Hi! I've built a daemon which spawns up to 32 threads. This part is ok, everything thing runs smoothly. Now i'd like to make these threads realtime threads as they are time critical and mustn't be delayed. I've tried many things but none seems to work (i check with htop / top to see the priority and GetThreadPriority on each of these thread inside the main thread). Code: [Select]procedure TMyThread.Create( ); override begin       inherited Create( True );       /* .. some initialization stuff ..  */       priority := tpTimeCritical;       ThreadSetPriority( GetCurrentThreadId, 15);       resume; end; Looking back at the thread in top/htop the thread stayed at priority 20. Trying ThreadSetPriority( GetCurrentThreadId, 15) always returns false (i'm root). What am i doing wrong ? Is top/htop the right place to see this information ? ---------------------------------------------------------------------- Greg · 2013-02-18 15:34 ok. found out this : http://bugs.freepascal.org/view.php?id=16785 Thread priority is not supported on Linux.... I was wondering if anyone tried pthread_getschedparam / pthread_setschedparam ? ---------------------------------------------------------------------- garlar27 · 2013-02-18 19:14 I never needed to set the thread's priority level. Never the less they normally if I don't use a WaitToEvent the threads eat resources like there's no tomorrow (like someone said in this forum). Your threads do not respond as quick as you need, or you just want all what system can give? ---------------------------------------------------------------------- Greg · 2013-02-19 07:49 Hi Garlar, The app needs to treat in realtime multicast udp packet. I have to be sure that this app has always the priority over other processes (like a http server). It's expected that the CPU will run at 80% consistently (a huge udp bandwidth is used). I tried to use daemon-start-stop parameters to set to realtime the processus, but threads build don't inherit these parameters. :/ ---------------------------------------------------------------------- Greg · 2013-02-19 08:28 ok. I found this http://www.mail-archive.com/fpc- devel@lists.freepascal.org/msg17552.html. Code: [Select] uses  cthreads, unixtype, pthreads; ... type    TClassPriority = (cprOther, cprFIFO, cprRR); ... function SetThreadPriority( aThreadID : TThreadID; class_priority : TClassPriority; sched_priority: Integer ) : Boolean; var    param : sched_param;    ret : Integer;    aPriority : integer; begin      // 0-99      param.sched_priority:= sched_priority;      aPriority := Ord(class_priority);      ret := pthread_setschedparam( pthread_t(aThreadID), aPriority, @param);      result := (ret = 0); end; It's working well!. ---------------------------------------------------------------------- bonmario · 2015-09-23 17:24 On my Ubuntu 15.04 64 it don't works. With cprOther, i have the error 22 Code: [Select]EINVAL      = 22;   { Invalid argument } With cprFIFO and with cprRR, i have error 1: Code: [Select]EPERM       = 1;    { Operation not permitted } Hi, Mario