The difference between the tcriticalsection and the trtlcriticalsection of the critical section object

Source: Internet
Author: User

Trtlcriticalsection is a struct, defined in a Windows cell; initializecriticalsection, EnterCriticalSection, LeaveCriticalSection, deletecriticalsection and so on these several kernel32.dll in the critical section operation API parameters; Tcriticalsection is the class implemented in the SYNCOBJS unit,  It encapsulates the above critical section Operations API functions, simplifying and facilitating the use of Delphi, such as Tcriticalsection.enter, which calls the EnterCriticalSection API function.  In a multithreaded program, if each thread accesses the same resource, as if a variable were to use thread synchronization technology, there are many ways to create conflicts between threads and interfere with thread synchronization, and using a critical section is the simplest and most efficient method (with the least CPU time) to use the critical section code as follows: Declare a global variable of type trtlcriticalsection firstvarmycs:trtlcriticalsection; Initialize the InitializeCriticalSection (MYCS) before the program starts or creates a thread;//Initialize critical sectionDelete it deletecriticalsection (MYCS) After the end of the program or all threads;//Delete a critical sectionadd EnterCriticalSection (MYCS) where you want to synchronize in the thread;//Enter the critical section    Try      //Program Code    finallyleavecriticalsection (MYCS);//leave the critical section    End;

Goto-critical Section object Tcriticalsection differs from Trtlcriticalsection

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.