Global variable vs Events in multi threading

drjackool 956 Reputation points
2021-09-13T08:57:10.22+00:00

hi
In Win32 apps (VC++) what is difference between using global variable and events to signal the thread?
What are pros and cons
Thanks

Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,772 questions
0 comments No comments
{count} votes

Accepted answer
  1. RLWA32 49,311 Reputation points
    2021-09-13T09:20:04.297+00:00

    One obvious difference is that a thread would poll to detect a change in a global variable while the wait functions with an event avoid polling. Or, you could use WaitOnAddress but that comes with its own considerations - WaitOnAddress lets you create a synchronization object out of any data variable, even a byte

    1 person found this answer helpful.
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Xiaopo Yang - MSFT 12,731 Reputation points Microsoft External Staff
    2021-09-14T08:12:15.603+00:00
    0 comments No comments

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.