Following the manual, the function int pth_wait(pth_event_t
ev) must return the number of occurred events.
In fact, it returns the total number of event in the event ring
ev.
The attached source file shows this bug.
The error was easy to find.
In the file pth_event.c, in the definition of the pth_wait function,
we can read:
/* count number of actually occurred events */
ev = ev_ring;
occurred = 0;
do {
occurred++;
pth_debug2("pth_wait: occurred
event 0x%lx", (unsigned long)ev);
ev = ev->ev_next;
} while (ev != ev_ring);
/* leave to current thread with number of occurred
events */
pth_debug2("pth_wait: leave to thread \"%s\"", pth_current->name);
return occurred;
which calculates the total number of events in the event ring ev_ring.
A possible right source code would be :
/* count number of actually occurred events */
ev = ev_ring;
occurred = 0;
do {
if ( ev->ev_occurred ==
TRUE ) {
occurred++;
pth_debug2("pth_wait:
occurred event 0x%lx", (unsigned long)ev);
}
ev = ev->ev_next;
} while (ev != ev_ring);
/* leave to current thread with number of occurred
events */
pth_debug2("pth_wait: leave to thread \"%s\"", pth_current->name);
return occurred;
which calculates the number of actually occurred events.
Do you agree with me ?
Best regards,
David Dureau
-- David Dureau - Agent CEA/DIF/DCSA/SNEC - - e-mail : [EMAIL PROTECTED] - - tel bureau: 01 69 26 65 27 -
#include <pth.h> #include <stdio.h>
#define NBEVT 5 pth_event_t evt[NBEVT]; pth_event_t evtring = NULL; pth_msgport_t mp[NBEVT]; pth_message_t msg[NBEVT]; void *waitfor( void *arg ) { int nbevt = 0; int i, occurred ; nbevt = pth_wait( evtring ); for( occurred = 0, i = 0 ; i < NBEVT ; i++ ) { if ( pth_event_occurred( evt[i] ) == TRUE ) occurred++; } printf("Return <pth_wait> : %d\tNumber of occurred event(s) : %d\n",nbevt,occurred); pth_exit(NULL); return NULL; } void *theevent( void *arg ) { pth_msgport_put( mp[2], &(msg[2]) ); pth_msgport_put( mp[3], &(msg[3]) ); pth_exit(NULL); return NULL; } int main( int argc, char **argv ) { pth_attr_t attr; pth_t tidwait, tidevent; int i; char name[1024]; pth_init(); evtring = NULL; for( i = 0 ; i < NBEVT ; i++ ) { sprintf(name,"port%d",i); mp[i] = pth_msgport_create(name); evt[i] = pth_event( PTH_EVENT_MSG, mp[i] ); if ( evtring == NULL ) evtring = evt[i]; else evtring = pth_event_concat( evtring, evt[i], NULL ); } attr = pth_attr_new(); pth_attr_init(attr); tidwait = pth_spawn( attr, waitfor, NULL ); tidevent = pth_spawn( attr, theevent, NULL ); pth_join( tidwait, NULL ); pth_join( tidevent, NULL ); for( i = 0 ; i < NBEVT ; i++ ) { pth_event_free( evt[i], PTH_FREE_THIS); pth_msgport_destroy( mp[i] ); } pth_attr_destroy( attr ); pth_kill(); return 0; }