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. Critical Section for one thread

Critical Section for one thread

Scheduled Pinned Locked Moved C / C++ / MFC
4 Posts 2 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.
  • F Offline
    F Offline
    Force Code
    wrote on last edited by
    #1

    How would you implement a critical section between two or more windows in a single thread, i.e. if one winproc tries to access it, it halts in place till its available, while other windows in thread continue to function and continue to recieve messages. I know CriticalSections work for threads, not windows - I was thinking of something implemented with GetMessage, PeekMessage or whatever. Maybe this is impossible.

    M 1 Reply Last reply
    0
    • F Force Code

      How would you implement a critical section between two or more windows in a single thread, i.e. if one winproc tries to access it, it halts in place till its available, while other windows in thread continue to function and continue to recieve messages. I know CriticalSections work for threads, not windows - I was thinking of something implemented with GetMessage, PeekMessage or whatever. Maybe this is impossible.

      M Offline
      M Offline
      Mark Salsbery
      wrote on last edited by
      #2

      If you only have one thread there's no way to halt that thread and have anything else happen in your windows or window proc(s) (aside from asynchronous callbacks, of course, but those are separate threads). With a single thread, while a windowproc is handling a message, all other window procs are halted. Mark

      Mark Salsbery Microsoft MVP - Visual C++ :java:

      F 1 Reply Last reply
      0
      • M Mark Salsbery

        If you only have one thread there's no way to halt that thread and have anything else happen in your windows or window proc(s) (aside from asynchronous callbacks, of course, but those are separate threads). With a single thread, while a windowproc is handling a message, all other window procs are halted. Mark

        Mark Salsbery Microsoft MVP - Visual C++ :java:

        F Offline
        F Offline
        Force Code
        wrote on last edited by
        #3

        Mark Salsbery wrote:

        If you only have one thread there's no way to halt that thread and have anything else happen in your windows or window proc(s) (aside from asynchronous callbacks, of course, but those are separate threads). With a single thread, while a windowproc is handling a message, all other window procs are halted.

        Well, if a resource is unavailable, why couldn't a WinProc start a GetMessage-Translate-Dispatch loop right there until a special message was sent indicating the resource was available, at which point the WinProc would halt the GetMessage Loop and continue as normal. I'm not understanding why this doesn't work.

        M 1 Reply Last reply
        0
        • F Force Code

          Mark Salsbery wrote:

          If you only have one thread there's no way to halt that thread and have anything else happen in your windows or window proc(s) (aside from asynchronous callbacks, of course, but those are separate threads). With a single thread, while a windowproc is handling a message, all other window procs are halted.

          Well, if a resource is unavailable, why couldn't a WinProc start a GetMessage-Translate-Dispatch loop right there until a special message was sent indicating the resource was available, at which point the WinProc would halt the GetMessage Loop and continue as normal. I'm not understanding why this doesn't work.

          M Offline
          M Offline
          Mark Salsbery
          wrote on last edited by
          #4

          Because that "GetMessage-Translate-Dispatch loop" is running on the same thread you start it on.  Everything occurs serially until there's another thread. Mark

          Mark Salsbery Microsoft MVP - Visual C++ :java:

          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