Experts help with Threads with Notifications
-
Sir, I am developing an Win32 application that involves events and notification. I am developing a simulator that fires an event and generates notification through threads. Pls correct me If I am going wrong. 1. Develop a Win32 Application. 2. Inside Winmain, do the following. 2.1. Create a thread 2.2. Create a Handle 2.3. Call CreateEvent and assign the handle to the first. 2.4. Call the message loop 3. Inside the thread call WaitforMultipleObjects(); 3.1 Use switch case To catch the event 3.2 Now when appropriate events are fired ,I want to get notification. 3.3 Where will I declare events ? Will it be in the header file or in the dll. What further do I have to do to achieve this? Can somebody help me with a piece of code here? Regards Tiger
-
Sir, I am developing an Win32 application that involves events and notification. I am developing a simulator that fires an event and generates notification through threads. Pls correct me If I am going wrong. 1. Develop a Win32 Application. 2. Inside Winmain, do the following. 2.1. Create a thread 2.2. Create a Handle 2.3. Call CreateEvent and assign the handle to the first. 2.4. Call the message loop 3. Inside the thread call WaitforMultipleObjects(); 3.1 Use switch case To catch the event 3.2 Now when appropriate events are fired ,I want to get notification. 3.3 Where will I declare events ? Will it be in the header file or in the dll. What further do I have to do to achieve this? Can somebody help me with a piece of code here? Regards Tiger
Your simulator thread can post messages to a window, if your main thread created a window, or threads can post messages to each other with PostThreadMessage. You can only wait on, I think, 32 events at any given time, so you don't want EVERY possible thing your simulator can do to be a different synchronization event. It would be better to create a thread-safe queue, and your simulator thread puts 'data events' into the queue and posts a message or sets a synchronization event to indicate that data is available in the queue. The thread consuming the data can wait on the synchronization event and then go read the queue. If it is a window, it would go read the data queue and process data until it had read all items out of the queue, then it would be waiting again.
-
Your simulator thread can post messages to a window, if your main thread created a window, or threads can post messages to each other with PostThreadMessage. You can only wait on, I think, 32 events at any given time, so you don't want EVERY possible thing your simulator can do to be a different synchronization event. It would be better to create a thread-safe queue, and your simulator thread puts 'data events' into the queue and posts a message or sets a synchronization event to indicate that data is available in the queue. The thread consuming the data can wait on the synchronization event and then go read the queue. If it is a window, it would go read the data queue and process data until it had read all items out of the queue, then it would be waiting again.
Thx for the response. Should the events be defined in a header file. I call a function which is already defined in a dll /in my application. Will that function generates an event like I press a button which in turn calls a function. The event names should be defined #define. Can u help me with a code snippet. Regards Regards Yadagiri