Referencing the source code below, to execute the source ( console
prompt/command line ), I do the following:

A->setUPStuff
value = 165449152 = 0x9dc8dc0
A->
semSourceTest
semDestTest


Now start the test num_iterations could be any value. For test
purposes try 10.

A->
giveSema 10
[num_iter=10
]value = 0 = 0x0
A->+.:x-50,0
:-o-51,1
:+x-50,0
:-o-51,1
:+x-50,0
:-o-51,1
:+x-50,0
:-o-51,1
:+x-50,0
:-o-51,1


As expected the result get displayed in alternating
fashion(50/51/50/51 etc) for 'N' interations.

We'd like to simulate a failure. To do this I'll set GENERATE_ERROR
to 1. So now at the command line:

A->GENERATE_ERROR =1

The result:

A->giveSema 10
[num_iter=10
]value = 0 = 0x0
A->+.:x-50,0
:-reallyBogus
:+-reallyBogus
:+-reallyBogus
:+Err
ErrDest

Sure enough we've got failures. Now lets 'reset' GENERATE_ERROR back
to zero ( ideal world case). At the console prompt:

A->GENERATE_ERROR=0

Now I'll run the program again.

A->giveSema 4
[num_iter=4
]value = 0 = 0x0
A->.:x-50,0
:+-o-51,1
-51,1
:+-o-51,1

Notice, here that my result here no longer mirrors that of my desired
result above: i.e the result is no longer 50/51/50/51 etc. It is my
belief that the issue lies with the counting semaphore startTransfer
within the task semSourceTest . The question, then becomes. What
can I do to -literally' reset starTransfer, such that I'll be in synch
again - after GENERATE_ERROR's?

Ideally, instead of printing "reallyBogus" once an error has
encountered, I'd like for the task semDestTest to send a semaphore -
or set a value (preferably) that semSourceTest could check and as such
'reset' the counting semaphore starTransfer.

Trouble is, I'm unsure how to achieve this.

With the exception of the vxWorks includes, the source compiles. The
code.

SEM_ID semTest ;
SEM_ID starTransFer ;
SEM_ID starterSema ;
SEM_ID destSema [ 2 ] ;
int bogus = -1 ;

volatile int m_index = 0 ;
int num_iter = 0 ;
extern "C" void semDestTest() {
printf ( "\nsemDestTest" ) ;

while ( 1 ) {

if ( semTake ( starterSema, WAIT_FOREVER ) != OK ) {
printf ( "DestCrap\n" );
}
printf ( "." ) ;
int my_index = 0 ;
semGive ( starTransFer ) ; // kick start source
bool bad_flag = false ;
int mprev = -1 ;
for ( int odx = 0; odx < num_iter; ++odx ) {
printf ( ":" ) ;
if ( semTake ( destSema [ my_index ], 80 ) != OK ) {
printf ( "ErrDest\n") ;
break ;
}
switch ( bogus ) {
case 50 :
printf ("x-%d,%d\n", bogus, m_index ) ;
if ( m_index != 0 ) {
printf ("E1\n" ) ;
bad_flag = true ;
}
else {
semGive ( starTransFer );
}

break ;
case 51 :
printf ("o-%d,%d\n", bogus, m_index ) ;
if ( m_index != 1 ) {
printf ("E2\n" ) ;
bad_flag = true ;
}
else {
semGive ( starTransFer );
}
break ;
default :
printf ( "reallyBogus\n" ) ;
bad_flag = true ;
break ;
}
if ( !bad_flag ) {
my_index ^= 1 ;
}
}
}
}

int GENERATE_ERROR = 0 ;
extern "C" void semSourceTest ( ) {
printf ( "\nsemSourceTest\n" ) ;

while ( 1 ) {

if ( semTake ( semTest, WAIT_FOREVER ) != OK ) {
printf ( "oops\n" ) ;
continue ;
}
int m_buffer = 0 ;

semGive ( starterSema ); // tell dest we're on our way
for ( int odx ( 0 ); odx < num_iter; ++odx ) {

if ( semTake ( starTransFer, 60 ) != OK ) {
printf ( "Err\n" );
break ;
}

if ( m_buffer ) {
printf ( "-" ) ;
m_index = 1 ;
if ( GENERATE_ERROR ) {
bogus = 99 ;
} else {
bogus = 51 ;
}
semGive ( destSema [ 1 ] ) ;
}
else {
printf ( "+" ) ;
m_index = 0 ;
bogus = 50 ;
semGive ( destSema [ 0 ] ) ;
}
m_buffer ^= 1 ;
taskDelay ( 2 ) ;
}
}
}

/*
| where it all starts
*/
extern "C" void giveSema ( int num_it ) {
num_iter = num_it;
printf ( "[num_iter=%d\n]", num_iter ) ;
semGive ( semTest ) ;
}

extern "C" void setUpStuff ( ) {

semTest = semCCreate ( 0, 0 ) ;
starTransFer = semCCreate ( 0, 2 ) ;
starterSema = semCCreate ( 0, 0 ) ;
for ( int odx = 0; odx < 2; ++odx ) {
destSema [ odx ] = semCCreate ( 0, 0 ) ;
}
kernelTimeSlice ( 30 ) ;
taskSpawn("dsrc", // name
60, // priority
VX_FP_TASK, // include floating point
operations (option)
10000, // stack size
(FUNCPTR)semSourceTest, // main
0, // arguments
0, 0, 0, 0,0,0,0,0,0);
taskSpawn("ddest", // name
60, // priority
VX_FP_TASK, // include floating point
operations (option)
10000, // stack size
(FUNCPTR)semDestTest, // main
0, // arguments
0, 0, 0, 0,0,0,0,0,0);

}

Thanks in advance