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,479 questions
0 comments No comments
{count} votes

Accepted answer
  1. RLWA32 41,996 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 11,746 Reputation points Microsoft Vendor
    2021-09-14T08:12:15.603+00:00
    0 comments No comments