After doing the above preparations, you need to add the command to start the thread and suspend the thread at the appropriate location in the main unit. The code looks like this:

1

4.3 About thread synchronization

Thread synchronization is very important in programming technology. When a thread accesses a process object, if another thread wants to change the object, it may produce wrong results. In the development application of this example, using the API function, you can directly use the critical or mutual exclusion to achieve the purpose of synchronization. In order to improve the reliability and flexibility of synchronization, both the flag variable and the critical mechanism are used. Simply declare a variable Sect1 of type TRTLCriticalSection in the program and initialize it in the constructor of the main thread. Then in a thread, the corresponding code can be marked as a critical part. When EnterCriticalSection() is called in a thread and Sect1 is passed, multiple data members are set to indicate that the critical part is active. If another thread wants to call its own critical part, the function EnterCriticalSection() will find that a critical part is in use, leaving the second thread to sleep until the first thread exits the critical part.

5 Conclusion

In this paper, C++ builder multi-threading technology is applied to the software design of open CNC system, which effectively solves the thread synchronization problem, guarantees the real-time requirements of CNC software system, and achieves better application results.

Previous page

Posted on