Threads

Hi, I’ve a PLCNextEnginneer project calling a c++ programs. The c++ programs is used to understand threads logic, and is similar to the sample on gitghub (https://github.com/PLCnext/CppExamples/blob/master/Examples/ThreadExample/README.md#plcnext-engineer-project). So c++ program has: Component: where threads are implemented Program: where only port exchange is manage on execute Working thread works cyclically but not in Real time, execute works under ESM so in Real time. Is it correct? So if idle time for working thread is 10000 (10 s) and the programg is instanciates in a cyclical task of 1000ms (1 s) that means every execution of working thread code, the ports variables on ESM task are update 10 times? The thread is subject to any watchdog? What happens when the working thread excution time is greater than idle time?

Hello Samuele,

please find the answers to your questions below:

Working thread works cyclically but not in Real time, execute works under ESM so in Real time. Is it correct?
→ Yes, it is correct and very important to know for the implementation of the application!

So if idle time for working thread is 10000 (10 s) and the programg is instanciates in a cyclical task of 1000ms (1 s) that means every execution of working thread code, the ports variables on ESM task are update 10 times?
→ Yes, the ESM program will read In the IN-Port variables and update the OUT-Port variables every second.
→ Please note, the thread works cyclically but not in Real time. That means that the thread will be started every 10s but it can be interrupted e.g. by ESM-Task and the execution time can be also 12s. If you would like to use a real-time Thread you have to implement also a thread WD to ensure the Thread execution/duration time (see the following SampleRuntime Example: https://github.com/PLCnext/SampleRuntime).

The thread is subject to any watchdog? What happens when the working thread excution time is greater than idle time?
→ If the thread needs little more time as e.g. >10s and <15s, the system WD will be not triggered, beacuse it is not critical. But if you implement a endless Loop, the Sytem WD will be triggered because the systems detect it as a dead-lock or endless while loop or .. or ..

In general, the threads are used for non-critical program parts that work in a non-real-time area, e.g. Measurement of room temperature or user shell interfaces.

I hope it helps you, if you have additional questions, please don’t hesitate to ask!

Best Regards
Eduard

Hi Eduard, thank you for your reply. Some other question: Why should I to implement a Real Time Thread? In this case i think is better implement a simple c++ project using execute in the program, what I didn’t regard? There is any rule to know the longer execution time admitted for thread in order to avoid any system WD? The system WD you spoke about isn’t the thread WD, right? I implement the sample thread project, and when i power off then power off the AXC2152 (with FW 2020.6.1) I always had an error, please look at the picture attacched. Do you have some suggestion? Samuele

Hello Samuelle please find the answers to your questions below: Why should I to implement a Real Time Thread? In this case i think is better implement a simple c++ project using execute in the program, what I didn’t regard? → Yes, program execution in a ESM Task is the easiest and most efficient way. The possibility of real-time thread implementation is particularly interesting for customers who do not want to work with plcnext runtime / PLCnext Engineer. There is any rule to know the longer execution time admitted for thread in order to avoid any system WD? → Yes, at first you have to ensure that your code is free of endless loop or dead locks. If you implement e.g. a Worker Thread and define the cyclic time, I wold like to recommend you to set this time rational. If you know that your program duration time needs 1000ms, it make not sence to set the Worker Thread cycle to 10ms. It is also possible to measure the program duration time based on system clock. Generally it is not neccessary to implement the WD for Thread, because the code will be not executed in real time, but the basic rules of programming should be observed.

The system WD you spoke about isn’t the thread WD, right?
→ Yes, te thread WD should be implement separately (if needed), the system WD ensure that all components will be executed.
I implement the sample thread project, and when i power off then power off the AXC2152 (with FW 2020.6.1) I always had an error, please look at the picture attacched. Do you have some suggestion? → The Power off case is not part of the operating mode; the power supply must be ensured for error-free controller operation. I hope this answers will help you, if you need more detailed information, please use the following link to Info Center: https://www.plcnext.help/te/About/Home.htm[

](Home)Best Regards, Eduard