→ index of namespace default
 
→ index of project core
 
→ index of module core

Class core.Thread


Synopsis: Represents a simultaneously running program task.

  Base classes:
  Methods:
  Constants: Description:


A thread may run on a different processor (if available).
Each thread has a mailbox that can be used to receive messages from other threads.


See also:  


 
→ top of page

Method allocEventQueue
Allocate mailbox event queue/ring buffer.
Signature
allocEventQueue(intsize)
Arguments
intsize–Maximum number of events that can be posted without discarding old events.

 
→ top of page
Method create
Signature
create(FunctionentryFunction)
 :boolean
Arguments
FunctionentryFunction–Function object to be used for thread startup. The arbitrary user argument can be accessed by using the Thread.getUserData() getter function.
Returns
boolean–

 
→ top of page
Method Delay
Put thread to sleep for a short time (low CPU load).
Signature
Delay()

 
→ top of page
Method getId
Return thread id (platform-specific).
Signature
getId():int
Returns
int–Thread id

 
→ top of page
Method GetMaxAffinityMask32
Pseudo-static method. Queries maximum supported affinity mask ( (1<<numProcessors)-1 ).
Signature
GetMaxAffinityMask32():int
Returns
int–

 
→ top of page
Method getName
Query thread name (debug)
Signature
getName():String
Returns
String–

 
→ top of page
Method GetNumCPUCores
Query number of logical CPU cores
Signature
GetNumCPUCores():int
Returns
int–
Description
@ret number of logical CPU cores

 
→ top of page
Method getPriority
Query thread priority
Signature
getPriority():int
Returns
int–Thread priority

 
→ top of page
Method getUserData
Get thread user data
Signature
getUserData():Object
Returns
Object–User-data object (reference)

 
→ top of page
Method IsAffinityMaskStringBitSet
Pseudo-static method. Test if the given bit is set in the affinity string mask.
Signature
IsAffinityMaskStringBitSet(intbit)
 :boolean
Arguments
intbit–0..63
Returns
boolean–

 
→ top of page
Method IsCPUCoreShared
Signature
IsCPUCoreShared(intcoreIdx)
 :boolean
Arguments
intcoreIdx–Logical CPU core index @ret true when logical CPU shares HW resources with other core (hyper threading)
Returns
boolean–

 
→ top of page
Method IsCPUCoreShared
Signature
IsCPUCoreShared(intcoreIdx)
 :boolean
Arguments
intcoreIdx–Logical CPU core index @ret true when logical CPU is an efficiency performance core (big/little systems)
Returns
boolean–

 
→ top of page
Method IsPerformanceCPUCore
Signature
IsPerformanceCPUCore(intcoreIdx)
 :boolean
Arguments
intcoreIdx–Logical CPU core index @ret true when logical CPU is a performance core (big/little systems)
Returns
boolean–

 
→ top of page
Method isRunning
Query whether thread is currently running
Signature
isRunning():boolean
Returns
boolean–

 
→ top of page
Method kill
Terminate thread
Signature
kill()

 
→ top of page
Method peekEvent
Return next pending event without removing it from the queue.
Signature
peekEvent():Event
Returns
Event–Pending event or null

 
→ top of page
Method peekEventById
Return next pending event whose id matches "id" without removing it from the queue.
Signature
peekEventById(intid)
 :Event
Arguments
intid–
Returns
Event–Pending event or null

 
→ top of page
Method rand
Generate random number (thread-safe)
Signature
rand():int
Returns
int–Random integer

 
→ top of page
Method sendEvent
Post new message in mailbox.
Signature
sendEvent(Eventev)
Arguments
Eventev–New message
Description

This will clone the given Event object and unlink any deletable userdata object from "ev".

 
→ top of page
Method setAffinityMask32
Set thread affinity mask.
Signature
setAffinityMask32(intmask)
Arguments
intmask–Logical processor core bit mask
Description

Keep in mind that this call will fail on Windows if the mask contains bits for non-available processor cores.Please use GetMaxAffinityMask32() to query the maximum supported mask.
This method is not supported on macOS.

 
→ top of page
Method setAffinityMaskByString
Set thread affinity mask.
Signature
setAffinityMaskByString(Stringmask)
Arguments
Stringmask–Logical processor core bit mask. 'x' denotes set bits, '.' denotes cleared bits, space/tab/CR/LF are ignored and can be used for grouping logical processors
Description

The mask is currently limited to 64 logical processors (todo: support processor groups).
Keep in mind that this call will fail on Windows if the mask contains bits for non-available processor cores.Please use GetMaxAffinityMask32() to query the maximum supported mask.
On macOS the mask should contain only a single set bit and the method will fall back to setCPUCore().

 
→ top of page
Method setCPUCore
Assign thread to specified CPU core.
Signature
setCPUCore(intcoreIdx)
Arguments
intcoreIdx–Logical CPU core index
Description

Fall back to setAffinityMask32() when tks was not compiled with HAVE_WIN10 define.

 
→ top of page
Method setName
Set thread name (debug)
Signature
setName(Stringname)
Arguments
Stringname–

 
→ top of page
Method setPriority
Set thread priority
Signature
setPriority(intprio)
Arguments

 
→ top of page
Method SetProcessAffinityMask32
Set process affinity mask (Windows only).
Signature
SetProcessAffinityMask32(intmask)
 :boolean
Arguments
intmask–Logical processor core bit mask
Returns
boolean–true when the system call succeeded, false otherwise.

 
→ top of page
Method SetProcessAffinityMaskByString
Set process affinity mask (Windows only).
Signature
SetProcessAffinityMaskByString(Stringmask)
 :boolean
Arguments
Stringmask–Logical processor core bit mask. 'x' denotes set bits, '.' denotes cleared bits, space/tab/CR/LF are ignored and can be used for grouping logical processors
Returns
boolean–true when the system call succeeded, false otherwise.
Description

The mask is currently limited to 64 logical processors (todo: support processor groups).
This method is not supported on macOS.

 
→ top of page
Method SetProcessPriorityClass
Set process priority class (Windows only).
Signature
SetProcessPriorityClass(intpriorityClass)
Arguments
intpriorityClass–One of PROCESS_PRIORITY_CLASS_IDLE, PROCESS_PRIORITY_CLASS_NORMAL, PROCESS_PRIORITY_CLASS_HIGH, or PROCESS_PRIORITY_CLASS_REALTIME

 
→ top of page
Method setUserData
Set thread user data
Signature
setUserData(Objecto)
Arguments
Objecto–User-data object (reference)

 
→ top of page
Method srand
Set random seed (thread-safe)
Signature
srand(intseed)
Arguments
intseed–Random seed

 
→ top of page
Method SwitchToThread
Schedule next waiting thread.
Signature
SwitchToThread()

 
→ top of page
Method wait
Wait for thread
Signature
wait():int
Returns
int–

 
→ top of page
Method waitEvent
Return next pending event or wait for new event to arrive.
Signature
waitEvent(inttimeoutMS)
 :Event
Arguments
inttimeoutMS–0=wait forever, millisec. until timeout otherwise
Returns
Event–Event or null (timeout or interrupt)
Description

Please notice that this method returns null in case the wait() timed out or got interrupted.

 
→ top of page
Method waitEventById
Return next pending event whose id matches "id" or wait for new matching event to arrive.
Signature
waitEventById(intid,
  inttimeoutMS 
  )  
 :Event
Arguments
intid–
inttimeoutMS–0=wait forever, millisec. until timeout otherwise
Returns
Event–Event or null (timeout or interrupt)
Description

Please notice that this method returns null in case the wait() timed out or got interrupted.

 
→ top of page
Method Yield
Schedule next waiting thread (same as SwitchToThread())
Signature
Yield()
Description

Can cause high CPU load when no other threads are waiting to be scheduled.

 
→ top of page
Constant PROCESS_PRIORITY_CLASS_HIGH (int)
Constant PROCESS_PRIORITY_CLASS_IDLE (int)
Constant PROCESS_PRIORITY_CLASS_NORMAL (int)
Constant PROCESS_PRIORITY_CLASS_REALTIME (int)
Constant THREAD_PRIORITY_ABOVE_NORMAL (int)
Constant THREAD_PRIORITY_BELOW_NORMAL (int)
Constant THREAD_PRIORITY_HIGHEST (int)
Constant THREAD_PRIORITY_IDLE (int)
Constant THREAD_PRIORITY_LOWEST (int)
Constant THREAD_PRIORITY_NORMAL (int)
Constant THREAD_PRIORITY_TIME_CRITICAL (int)

 

Project Modules:core 
Project Classes:Boolean , Buffer , Byte , Class , ClassArray , Condition , Configuration , Double , DummyStream , Envelope , Event , Exception , File , Float , FloatArray , FloatArray128 , FloatArray16 , FloatArray32 , FloatArray64 , FloatArray8 , Function , HashTable , IntArray , IntArray128 , IntArray16 , IntArray32 , IntArray64 , IntArray8 , Integer , LFSR , LFSR_NR , List , ListNode , Long , Mailbox , Mutex , Object , ObjectArray , PakFile , PointerArray , Pool , Process , Script , SharedBuffer , Short , Stack , StdErrStream , StdInStream , StdOutStream , Stream , String , String128 , String16 , String32 , String64 , String8 , StringArray , StringIterator , Thread , Time , TKS , TreeNode , UnsignedByte , UnsignedInteger , UnsignedLong , UnsignedShort , Value , ValueArray , Variable 
Project Functions:ceil , exit , floor , GetCurrentThread , getenv , lcchar , mathAbsMaxf , mathAbsMinf , mathAbsMini , mathAbsMini , mathCerpf , mathClampf , mathClampi , mathDistancePointPlane2d , mathFoldf , mathFoldi , mathGCD , mathLerpCyclicf , mathLerpf , mathMaxf , mathMaxi , mathMinf , mathMini , mathNextCyclicf , mathPowerf , mathPowerfC , mathPoweri , mathSerpf , mathSmoothStepf , mathSmoothStepNf , mathWrapf , mathWrapi , milliSeconds , milliSecondsDouble , psystem , putenv , srand , system , ucchar 
All Namespaces:default , graph , ui 
All Projects:core , eqxmms , ShaderVG , ShaderVG_Text , tkanalogrytm , tkchipmunk , tkclap , tkfileutils , tkfreeglut , tkfreetype2 , tkfreeverb , tkmath , tkmidi , tkmidipipe , tkminnie , tkoldmath , tkopengl , tkportaudio , tkradiastools , tksamplechain , tksampleedit , tksampler , tksdl , tksdl_net , tksidplay2 , tkspeexdsp , tksqlite , tktriangulate , tkui , tkvst2 , tkzip , ui , yingtest 


auto-generated by "DOG", the TkScript document generator. Tue, 3/Mar/2026 18:10:17