Rockwell Automation 1789-L10_L30_L60 SoftLogix 5800 System User Manual User Manual

Page 135

Advertising
background image

Rockwell Automation Publication 1789-UM002J-EN-P - December 2012

135

Develop External Routines

Chapter 7

Thread Priorities in a Multithreaded External Routine DLL

If you use Microsoft C or C++ to develop your external routine, use only the
‘_beginthread’ C runtime function, as shown above in the example. By using the
‘_beginthread’ and ‘_endthread’ calls verifies that the system resources are
properly allocated by the Microsoft C runtime library.

When developing a multithreaded DLL, you must link with the multithreaded
version of the C runtime library. Use the Multithreaded DLL option in your
project settings for the run-time library option.

Keep in mind that the default priority assigned to a thread upon its creation is
THREAD_PRIORITY_NORMAL. This priority level (priority level 2) is
reserved for running the controller's periodic tasks. Set the priority of the newly
created thread to something more appropriate so as not to interfere with the
execution of periodic tasks in the controller. The example above shows how to set
the thread priority to be equal to the priority of the parent thread, or
THREAD_PRIORITY_IDLE if the thread does not perform any time-critical
operations.

The following table shows the mapping between thread priorities and the
controller's task priorities:

Continuous TaskTHREAD_PRIORITY_LOWEST
Periodic Task (pri. 3)THREAD_PRIORITY_BELOW_NORMAL
Periodic Task (pri. 2)THREAD_PRIORITY_NORMAL
Periodic Task (pri. 1)THREAD_PRIORITY_ABOVE_NORMAL

If you do not set the priority of a thread created via the “_beginthread” runtime
function to the recommended values, periodic task overlap faults or watchdog
faults can occur.

ATTENTION: Do not set the priority of any thread to a value greater than
THREAD_PRIORITY_ABOVE_NORMAL because it will interfere with the
operation of critical controller system threads and may result in unpredictable
behavior of the controller.

Advertising