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. a question about event object

a question about event object

Scheduled Pinned Locked Moved C / C++ / MFC
question
5 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.
  • Z Offline
    Z Offline
    zengkun100
    wrote on last edited by
    #1

    There is an autoreset event object ,and it's initial state is signaled. Suppose there are two threads in a process, called A and B, are wating for this event object infinitely. Either thread will change the event's state to nonsignaled if it's waiting function call succeeds, and the other thread will still wait on that object. Am I right? If thread A's waiting funcion call succeeds, then before it call ResetEvent, A terminated. How about B, Will B still wait for this event object? The event object's is signaled, or nonsignaled? Thank you all :)

    J 1 Reply Last reply
    0
    • Z zengkun100

      There is an autoreset event object ,and it's initial state is signaled. Suppose there are two threads in a process, called A and B, are wating for this event object infinitely. Either thread will change the event's state to nonsignaled if it's waiting function call succeeds, and the other thread will still wait on that object. Am I right? If thread A's waiting funcion call succeeds, then before it call ResetEvent, A terminated. How about B, Will B still wait for this event object? The event object's is signaled, or nonsignaled? Thank you all :)

      J Offline
      J Offline
      JudyL_MD
      wrote on last edited by
      #2

      ResetEvent is only used for manual events. You are talking about auto-reset events. Auto reset means that the event automatically returns to the non-signalled state after a thread which was waiting for the event to be signalled is released. If thread A, which was released, terminates before it calls SetEvent to signal the event, thread B will be stuck waiting since there is nothing to change the state of the event to signalled. Judy

      Z 1 Reply Last reply
      0
      • J JudyL_MD

        ResetEvent is only used for manual events. You are talking about auto-reset events. Auto reset means that the event automatically returns to the non-signalled state after a thread which was waiting for the event to be signalled is released. If thread A, which was released, terminates before it calls SetEvent to signal the event, thread B will be stuck waiting since there is nothing to change the state of the event to signalled. Judy

        Z Offline
        Z Offline
        zengkun100
        wrote on last edited by
        #3

        Thank you JudyL_FL! I have try it, and found that thread B will be waiting for ever, hence it will have no chance to execute. So I think it would be dangerous to use autoreset event to synchronous threads. :)

        J 1 Reply Last reply
        0
        • Z zengkun100

          Thank you JudyL_FL! I have try it, and found that thread B will be waiting for ever, hence it will have no chance to execute. So I think it would be dangerous to use autoreset event to synchronous threads. :)

          J Offline
          J Offline
          JudyL_MD
          wrote on last edited by
          #4

          zengkun100 wrote:

          So I think it would be dangerous to use autoreset event to synchronous threads

          It all depends on how the threads are synchronized. Each has its place. Refer to the MSDN for an example that uses both. Using Event Objects[^]. Manual reset events can also cause deadlocks if a thread terminates before it signals the event. Synchronization and the avoidance of deadlocks are one of the big issues when doing multi-threading. Judy

          Z 1 Reply Last reply
          0
          • J JudyL_MD

            zengkun100 wrote:

            So I think it would be dangerous to use autoreset event to synchronous threads

            It all depends on how the threads are synchronized. Each has its place. Refer to the MSDN for an example that uses both. Using Event Objects[^]. Manual reset events can also cause deadlocks if a thread terminates before it signals the event. Synchronization and the avoidance of deadlocks are one of the big issues when doing multi-threading. Judy

            Z Offline
            Z Offline
            zengkun100
            wrote on last edited by
            #5

            Thank you Judy :) Each coin has two sides, I will think more about thread synchronization.

            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