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. Multiple Threads

Multiple Threads

Scheduled Pinned Locked Moved C / C++ / MFC
questionc++sysadminhelp
2 Posts 2 Posters 1 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.
  • A Offline
    A Offline
    Andrew 0
    wrote on last edited by
    #1

    Hi, I have a few questions about Multi-threading with MFC. 1. With the function you supply in the first parameter of AfxBeginThread, - the new thread calls this function- if you have multiple threads calling this function, is a new instance of the function created or is it used by all threads? ie AfxBeginThread( UpdateClients, this ) If you create 3 threads, do these 3 threads all share the same instance of UpdateClients? Wouldn't make a lot of sense if they did...but just curious. 2. I'm creating a client/server application which has basic transfer/sending capabilities. I was intending to create a seperate thread for each dialog box used to indicate how much a file has been sent/receive. What is the best method for doing this? Should I use CWinThread? The tutorials for using GUI threads confused me more. Thanks for your Help

    N 1 Reply Last reply
    0
    • A Andrew 0

      Hi, I have a few questions about Multi-threading with MFC. 1. With the function you supply in the first parameter of AfxBeginThread, - the new thread calls this function- if you have multiple threads calling this function, is a new instance of the function created or is it used by all threads? ie AfxBeginThread( UpdateClients, this ) If you create 3 threads, do these 3 threads all share the same instance of UpdateClients? Wouldn't make a lot of sense if they did...but just curious. 2. I'm creating a client/server application which has basic transfer/sending capabilities. I was intending to create a seperate thread for each dialog box used to indicate how much a file has been sent/receive. What is the best method for doing this? Should I use CWinThread? The tutorials for using GUI threads confused me more. Thanks for your Help

      N Offline
      N Offline
      Nick Hodapp
      wrote on last edited by
      #2

      Andrew: A couple of pointers: 1. A function doesn't really have an "instance" in the way a variable does. All threads calling a function are invoking the same code -- Windows doesn't keep multiple copies of the code in memory. Each thread does have its own call stack -- which tracks the state of the program-execution for that thread. Lastly, note that if the function has a static variable declared within, that variable will be shared between threads unless it is set to use thread-local storage. 2. You _can_ have your dialogs running on other threads, and CWinThread is a fine way to achieve this. However, I would consider keeping the GUI elements on the main thread and placing your processing code on another. In this case, your dialogs can simply be modeless and query the worker thread they are associated with for a periodic status update. Either way will work, and it's debatable what is a "better" solution. Personally, I like to keep the GUI on one thread, esp. if I'm using MFC. Regards, Nick Hodapp

      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