Newsgroups: comp.programming.threads
From: terek...@my-deja.com
Date: Thu, 25 Jan 2001 11:10:45 GMT
Local: Thurs, Jan 25 2001 6:10 am
Subject: Re: pthread_cond_* implementation questions
David Schwartz <dav...@webmaster.com> wrote: please read the source code again... >terek...@my-deja.com wrote: >> David Schwartz <dav...@webmaster.com> wrote: >> > ...it's buggy. >> well, please SHOW me the bug. >The bug is that you call 'pthread_cond_signal' which is only main thread can not steal any "ball" signals from players . >> > Players A and B use pthread_cond_signal, but it's possible... if the program's main thread would need to wait for signals >> It is not fair to claim that it's buggy just saying >> It would be another program then (with added new features). >Huh? while players are playing it would be another program. it could have been made to allow players to leave game Current program does not support/allow it hence main does not >> The program is intentionally designed to use signals well, it might be that the program is in fact buggy. >> (in order to demonstrate the problem with _signal call >> impl.) in such way that players need ALWAYS AND ONLY >> talk to each other or main() <- last player leaving the game, >> but NEVER to both (another player and main). >The problem is that the pthread_cond_signal doesn't know which thread but you did not show me any bug. >> main() commands (sets the state of game to be over) in the situation when player A's pthread_cond_signal >> players carry out (stop playing). >> Broadcast is only needed for final "game over" >Nonesense. You are only guaranteed that pthread_cond_signal wakes the main thread (that can only happen when game is over), player B will be unblocked by already happened broadcast from main (which declared the game to be over). >> > It's compliant well, you can probably loose your bet.. it was indeed stolen >> That is really good. >> Tomorrow (I have to go urgently now) I will try to >Signals aren't lost, they're going to the main thread, > // Wait for players to stop > pthread_cond_wait( &cndGameStateChange,&mtxGameStateLock ); > } while ( eGameState < BOTH_PLAYERS_GONE ); >I bet everytime you thing a signal is lost, you'll see that printf. by "another" thread but not the one you seem to think of. I think that what actually happens is the following: H:\SA\UXX\pt\PTHREADS\TESTS>tennis3.exe PLAYER-A PLAYER-B ----PLAYER-B: SPURIOUS WAKEUP!!! PLAYER-A GONE PLAYER-B GONE GAME OVER H:\SA\UXX\pt\PTHREADS\TESTS> here you can see that PLAYER-B after playing his first The implementation has a problem: ================ { /** Critical Section inc cond.waiters_count } /* /* Atomic only if using Win32 SignalObjectAndWait /* cond.mtx.release /*** ^^-- A THREAD WHICH DID SIGNAL MAY ACQUIRE THE MUTEX, cond.sem.wait Player-A after playing game's initial ball went into =============== { /** Critical Section waiters_count = cond.waiters_count } if ( waiters_count != 0 ) sem.post 1 endif Player-B after he received signal/ball from Player A It seems to me that the implementation fails to http://www.opengroup.org/ "These functions atomically release mutex and cause Question: Am I right? (I produced the program output above by simply ================ { /** Critical Section inc cond.waiters_count } /* /* Atomic only if using Win32 SignalObjectAndWait /* cond.mtx.release Sleep( 1 ); // Win32 /*** ^^-- A THREAD WHICH DID SIGNAL MAY ACQUIRE THE MUTEX, cond.sem.wait to the source code of pthread-win32 implementation: http://sources.redhat.com/cgi-bin/cvsweb.cgi/pthreads/ /* pthread_cleanup_push (ptw32_cond_wait_cleanup, (void *) if ((result = pthread_mutex_unlock (mutex)) == 0) /* pthread_cleanup_pop (1); /* Always cleanup */ BTW, on my system (2 CPUs) I can manage to get regards, Sent via Deja.com You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
| ||||||||||||||