InitializeCriticalSection

Pham Thi Hien 21 Reputation points
2021-07-31T05:25:22.627+00:00

Hello everyone

I have a question about InitializeCriticalSection.

Thank you for your support!

Windows development | Windows API - Win32
0 comments No comments
{count} votes

Accepted answer
  1. Viorel 122.6K Reputation points
    2021-07-31T06:42:10.887+00:00

    In my opinion, the next approach should work:

    1. When start program
       • Create file
       • InitializeCriticalSection
    2. Write file
       • EnterCriticalSection
       • Write file
       • If file > 2M then create new file
       • LeaveCriticalSection
    3. Create new file
       • Close current file
       • Create new file, make it current file
    4. End program
       • Close current file
       • DeleteCriticalSection

    or an alternative:

    1. When start program
       • InitializeCriticalSection
    2. Write file
       • EnterCriticalSection
       • If file not created then create file
       • Else If file > 2M then create new file
       • Write file
       • LeaveCriticalSection
    3. Create new file
       • Close current file
       • Create new file, make it current file
    4. End program
       • If file created then close file
       • DeleteCriticalSection

    You must also finish the threads before executing 4.

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.