Description
CDL does support the notion of a thread (THRD), but in practice they are only provided for special cases where control can block outside of the runtime scheduler; for example, where a thread needs to perform external I/O on a blockable device (e.g. reading from a socket). Circuit methods make more efficient use of system resources, and since their implementation also avoids the expense of operating system context switching, threads are seldom used in practice.
Methods should always be used in preference to 'threads' because they provide almost identical functionality (preemptive asynchronous execution) but consume a small fraction of the resources required by conventional threads. They are also load-balanced across entire networks, whilst threads are only scheduled within a single process (see Methods).
Definition Content
The following information is required in order to define a thread (THRD).
Stack Size
This attribute specifies the thread's stack requirement in bytes. Each thread element will require its own stack.
The follwoing information is required for threads that require 'thread specific' heaps. This is an advanced feature but can result in considerable performance gains under certain circumstances (see memory management).
Cache Size
Memory Cache size allocated for the Process. Default uses a proportion of the Heap Size depending on the Optimization.
Heap Size
Memory Heap size allocated for the Process. This is the main memory reserved by CLIP for this applications use.
Optimization
Heap Optimization specifies which optimization algorithm should be used, ie for speed 'Fast' or size 'Small'.
Timeliness
Timeliness controls the way memory is allocated. When set to Real-time, operations are guaranteed to complete within a particular worst case time, whereas Offline operations no deadlines are guaranteed. The Real-time option will typically produce more consistent results, whilst the Offline option will probably result in a faster throughput
Instance Content
The following information is required in order to instantiate a thread.
Name
Instance name (see Object Names)
Dimension
Instance dimensionality (see Object Dimensionality)
Presence
Instance presence flag (see Object Presence)
Execution Priority
Threads execute preemptively in accordance with their priority. CDL supports 32 execution priorities. Zero is the lowest execution priority and 31 is the highest.
Occasionally Over-Rideable Functions
The following functions have generated bodies that can be 'over-ridden' (see Browsing and Inserting User Code);
Create Function
This over-rideable function creates the THRD and is called automatically once only when its parent circuit instance is created.
Integrate Function
This over-rideable function populates the THRD's parent pointer and is called automatically once only when its parent circuit instance is integrated.
Connect Function
This over-rideable function connects the THRD's manual connection(s) and is called automatically once only when its parent circuit instance is connected.
Frequently Over-Rideable Functions
The following functions have generated bodies that usually require insertion of user code (see Browsing and Inserting User Code);
Initialize Function
This user defined function is entered using the Blueprint editor and is automatically called once only before the thread is first executed.
Execute Function
This user defined function is entered using the Blueprint editor and is automatically called when the application is activated.
Exit Function
This user defined function is entered using the Blueprint editor and is automatically called once only on process exit.
Member Functions
Circuit methods support the following member functions. None of these functions takes an argument.
Name()
Returns the address of a string containing the executing element's creation name.
NumDimensions()
Returns the number of dimensions that the executing instance was created with. This does not include the dimensionality of the parent circuit which can be obtained through use of the 'parent' member function (see below).
Dimensions()
Returns the address of an unsigned integer array containing the executing thread's creation dimensions. The first element of the array contains the fastest varying (rightmost) dimension.
Element()
Returns the address of an unsigned integer array containing the executing thread element's particular coordinates.
Parent()
Returns a reference to the executing thread's parent circuit. If the thread is defined in-line then the function will return a pointer of the parent circuit's derived instance type. If the thread is defined explicitly then it will return a reference of the base circuit type.
Workspace()
Returns a reference to the executing thread element's workspace object (see State and Workspace Objects).
Notes
None.
Examples
See Heavy vs. Light-Weight Execution.