Instructions
355 C-Control Pro IDE
© 2013 Conrad Electronic
active at all times even if no threads have explicitly been started.
If the main program (thread "0") terminates, all other threads stop, too.
The priority of threads can be influenced by changing the number of time cycles which one thread is
allowed to execute until the next thread change takes place. The smaller the number of cycles until
the change takes place, the lower the priority of the thread.
Thread Configuration
Before IDE version 2.12 the threads were configured in the project options. That has changed. The
configuration is now placed inside the source code with the new "#thread" keyword. The syntax is:
#thread thread_number, ram_used, number_of_time_cylces
A thread will receive as much space for its local variables as has been assigned to it. The exception
is thread "0" (the main program). This thread will receive the entire memory space that has been left
over by the other threads. The RAM assignment by the "#thread 0" statement for the main thread is
ignored. Therefore it should be planned in advance how much memory space may be needed by
each additional thread.
The "#thread" statements need not be near the thread functions, but may be anywhere in the
program. If no threads are used, a "#thread 0" command is unnecessary. If you forget to define a
thread, the thread_start is ignored.
Example CompactC:
#thread 0, 0, 20 // main thread with task change every 20 * 10ms =200ms
#thread 1, 128, 10 //thread 1 with 128 Byte & task change 10*10ms =100ms
#thread 2, 256, 10 //thread 2 with 256 Byte & task change 10*10ms =100ms
Example BASIC (syntax identical to CompactC):
#thread 0, 0, 20 ' main thread with task change every 20 * 10ms =200ms
#thread 1, 128, 10 ' thread 1 with 128 Byte & task change 10*10ms =100ms
#thread 2, 256, 10 ' thread 2 with 256 Byte & task change 10*10ms =100ms
Since e. g. Serial_Read will wait until a character arrives from the serial interface, a thread can in
some cases be active longer than the assigned number of time cycles.
When working with threads Thread_Delay rather than AbsDelay should always be used. If never-
theless e. g. an AbsDelay(1000) is used, the thread will wait for 1000ms even if a smaller number of
time cycles is assigned.
Thread Synchronization
Sometimes it is necessary for a thread to wait for another thread. This may e. g. be a common hard-
ware resource which can only execute one thread. Sometimes also critical program areas may be
defined which may only be entered by one thread. This functions are being realized through instruc-