Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Experts help with Threads with Notifications

Experts help with Threads with Notifications

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Lost User
    wrote on last edited by
    #1

    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

    B 1 Reply Last reply
    0
    • L Lost User

      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

      B Offline
      B Offline
      Blake Miller
      wrote on last edited by
      #2

      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.

      U 1 Reply Last reply
      0
      • B Blake Miller

        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.

        U Offline
        U Offline
        User 1149186
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups