Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.programming.threads > #3355

Re: WaitForMultipleObjects never wakes up - Windows-bug?

From Bonita Montero <Bonita.Montero@gmail.com>
Newsgroups comp.programming.threads
Subject Re: WaitForMultipleObjects never wakes up - Windows-bug?
Date 2016-05-23 12:55 +0200
Organization albasani.net
Message-ID <nhunin$prv$1@news.albasani.net> (permalink)
References <nhspns$15q$1@news.albasani.net>

Show all headers | View raw


I've got a solution for this problem.
In the main-thread, simply wait for the semaphore and then for the
event (in this order - or you're gonna deadlock) with WaitForSingle
Object. That's not so efficitent, but works.

int main()
{
     int const NTHREADS = 2;
     HANDLE    ahWait[2];

     ::hEvt  = CreateEvent( NULL, FALSE, TRUE, NULL );
     ::hSema = CreateSemaphore( NULL, 0, 1, NULL );
     fReleased = false;

     for( int i = 0; i < NTHREADS; i++ )
         CreateThread( NULL, 0, LockAndReleaseThread, NULL, 0, NULL );

     for( ; ; )
         WaitForSingleObject( ::hSema, INFINITE ),
         WaitForSingleObject( ::hEvt, INFINITE),
         printf( "main thread is holding lock and received signal\n" ),
         ::fReleased = false,
         SetEvent( ::hEvt );

     return 0;
}


-- 
http://facebook.com/bonita.montero/

---
Diese E-Mail wurde von Avast Antivirus-Software auf Viren geprüft.
https://www.avast.com/antivirus

Back to comp.programming.threads | Previous | Next — Previous in thread | Find similar | Unroll thread


Thread

WaitForMultipleObjects never wakes up - Windows-bug? Bonita Montero <Bonita.Montero@gmail.com> - 2016-05-22 19:19 +0200
  Re: WaitForMultipleObjects never wakes up - Windows-bug? Bonita Montero <Bonita.Montero@gmail.com> - 2016-05-23 12:55 +0200

csiph-web