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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. asynchronouse thread function

asynchronouse thread function

Scheduled Pinned Locked Moved C / C++ / MFC
c++data-structureshelp
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.
  • H Offline
    H Offline
    hrishi321
    wrote on last edited by
    #1

    hi to all i have this problem with win32 code. vc++ console based application. i have a module...where some inputs/messsages keeps coming.....what I want is to....wheneerv a message comes i want to put in a queue..and the reciever function returns the control...now i want to have a thread, which will keep looking onto the queue...if empty, do nothing....if not empty then process the message.... (reason : main reason to do this is...instead of having the while loop in the thread function, which will eat CPU cycle, i want some mechanism to do task only when needed)... please give me some solution to the problem....or is there anything(funtion/concept) available in win32 (vc++)... all i need to do is prcess the messages when queue is not empty, otherwise do nothing... thnaks in advance

    CPalliniC R 2 Replies Last reply
    0
    • H hrishi321

      hi to all i have this problem with win32 code. vc++ console based application. i have a module...where some inputs/messsages keeps coming.....what I want is to....wheneerv a message comes i want to put in a queue..and the reciever function returns the control...now i want to have a thread, which will keep looking onto the queue...if empty, do nothing....if not empty then process the message.... (reason : main reason to do this is...instead of having the while loop in the thread function, which will eat CPU cycle, i want some mechanism to do task only when needed)... please give me some solution to the problem....or is there anything(funtion/concept) available in win32 (vc++)... all i need to do is prcess the messages when queue is not empty, otherwise do nothing... thnaks in advance

      CPalliniC Offline
      CPalliniC Offline
      CPallini
      wrote on last edited by
      #2

      What about documentation: "Multithreading with C and Win32"? :)

      If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
      This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
      [My articles]

      In testa che avete, signor di Ceprano?

      1 Reply Last reply
      0
      • H hrishi321

        hi to all i have this problem with win32 code. vc++ console based application. i have a module...where some inputs/messsages keeps coming.....what I want is to....wheneerv a message comes i want to put in a queue..and the reciever function returns the control...now i want to have a thread, which will keep looking onto the queue...if empty, do nothing....if not empty then process the message.... (reason : main reason to do this is...instead of having the while loop in the thread function, which will eat CPU cycle, i want some mechanism to do task only when needed)... please give me some solution to the problem....or is there anything(funtion/concept) available in win32 (vc++)... all i need to do is prcess the messages when queue is not empty, otherwise do nothing... thnaks in advance

        R Offline
        R Offline
        Rajesh R Subramanian
        wrote on last edited by
        #3

        hrishi321 wrote:

        wheneerv a message comes i want to put in a queue..and the reciever function returns the control...now i want to have a thread, which will keep looking onto the queue...if empty, do nothing....if not empty then process the message....

        That's what the UI thread does (if you're using MFC).

        hrishi321 wrote:

        main reason to do this is...instead of having the while loop in the thread function, which will eat CPU cycle, i want some mechanism to do task only when needed)...

        WaitForSingleObject[^] could help you do this. A queued event thread is fairly easy to implement if you're not using MFC as well. All you need is a thread, a message queue and a couple of events that signals if there's more messages to be processed and if the thread should stop execution immediately (app shut down) and a WaitForSingleObject (or multiple objects, depending on how you do it) call that would be used for waiting on the said events. What have you thought of to solve this?

        “Follow your bliss.” – Joseph Campbell

        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