The TaskNew() will normally return before
the new cicode thread has completed. However this is not always the
case and you should not rely on the exact timing of the TaskNew()
function and the created cicode thread. This is because the exact
scheduling is based on the Citect kernel scheduler and is effected
by real time events, so it may change depending on what is
happening on your computer. If the new cicode thread is very small
and does not read any PLC data, then the new cicode thread may
terminate before the TaskNew() function has returned.
This is how the TaskNew() function actually operates:
- Create a new cicode thread control block.
- Make the cicode thread control block to point at the new
function and push the arguments onto the stack.
- If not using mode 4 (Request all I/O Device data before
starting task) in TaskNew(), or using mode 4 and the function
does not read any PLC variables then goto next step. Send the
request for the PLC data to the I/O server and put the cicode
thread into a wait state. The TaskNew() function will now return
before any cicode has been executed. When the data is returned from
the I/O server the cicode thread will awaken and will start
executing in parallel to the first cicode thread. This delay in
starting could be from a few milliseconds to several seconds.
- Schedule the cicode to start executing. The cicode scheduler is
designed to give higher priority for newly created cicode, so this
cicode will run immediately. The new cicode thread will keep
running until it is preempted by a higher priority Citect event or
run out of it's time slice. Once this cicode thread has been
preempted then the TaskNew() function will return. The new cicode
thread will continue to execute in parallel with the first cicode
thread.
|