This is the mail archive of the pthreads-win32@sourceware.cygnus.com mailing list for the pthreas-win32 project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

pthread_cond_broadcast()


Hi,

I'm somewhat new to pthreads programming, and especially new to the
win32 stuff. I'm trying to port some code from Linux to Windows NT, and
it seems to hang in the following case.

ThreadA {
 while(1) {
  pthread_cond_wait(cond, ...);
  /* do stuff */
 }
}

ThreadB {
  while(1) {
    pthread_cond_broadcast(cond, ...);
    /* do other stuff */
  }
}

The problem arises when there are are two instances of ThreadA (let's
call them A1 and A2), and one instances of thread B (call it B). When B
broadcasts a signal, A1 and A2 each wake up, respond to the signal, and
then go back to waiting. But B never gets switched back in after A1 and
A2 wait on the signal for the second time! 

I tried to test this by writing a smaller program which just does this
(attached to this e-mail). However, this smaller program seems to have
even bigger problems, the threads never respond to the broadcast, and I
have no clue why (it works just fine in Linux)! Could anybody offer any
assistance?

I am also attaching the makefile I used to compile the program (it
should work with both Microsoft's nmake utility, and the GNU make
utility, though I've been using nmake exclusively). (Note that the
include path and the library path are relative pathnames in the
makefile...)


Lorin Hochstein

thread_test.c

CC = cl.exe
LNK = link.exe
CFLAGS = /W3 /WX /MT /Z7
LIBS = pthread.lib
LIBPATH = /LIBPATH:..\pthreads
INC = /I..\pthreads
DEFINES = /D_WIN32_WINNT=0x400 /DSTDCALL=_stdcall

all: thread_test.obj
	$(LNK) /OUT:thread.exe $(LIBPATH) thread_test.obj $(LIBS)

thread_test.obj: thread_test.c
	$(CC) $(CFLAGS) $(DEFINES) $(INC) /c thread_test.c


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]