Thanks for replying.
I do realize the problem in joining something that doesn't exist.
But I cant find an alternative.
Code:
void *ethercat_cyclic_function()
{
printf( "Starting cyclic thread...\n" );
IO_digIn_t inputs;
IO_digOut_t outputs;
pthread_t vision_thread_ID;
while( 1 )
{
time_t now = clock();
time_t limit = now + CYCLE_TIME * CLOCKS_PER_SEC;
/********************************
* Update digital inputs *
********************************/
ecrt_master_receive( g_master );
ecrt_domain_process( g_domain );
unsigned char pdo_digIn1 = (unsigned char)EC_READ_U8( g_process_data + g_offInpMod1 );
inputs.pushbutton = pdo_digIn1 >> 1;
/********************************
* Update digital outputs *
********************************/
unsigned char pdo_digOut1 = 0;
pdo_digOut1 |= outputs.motor << 0 |
outputs.cylA << 1 |
outputs.cylB << 2 |
outputs.cylC << 3;
EC_WRITE_U8( g_process_data + g_offOutpMod1, pdo_digOut1 );
ecrt_domain_queue( g_domain );
ecrt_master_send( g_master );
/********************************
* Machine cycle *
********************************/
if( inputs.pushbutton )
{
pthread_mutex_lock( &g_vision_finished_LOCK );
if( g_vision_finished )
{
pthread_join( vision_thread_ID, NULL );
pthread_create( &vision_thread_ID, NULL, vision_thread, NULL );
}
pthread_mutex_unlock( &g_vision_finished_LOCK );
}
/********************************
* Whait... *
********************************/
while( now < limit )
now = clock();
}
}
Code:
void *vision_thread (void *arg)
{
pthread_mutex_lock(&g_vision_finished_LOCK);
g_vision_finished = 0;
pthread_mutex_unlock(&g_vision_finished_LOCK);
printf("Inside thread\n");
sleep(10); //Debugging dummy
pthread_mutex_lock(&g_vision_finished_LOCK);
g_vision_finished = 1;
pthread_mutex_unlock(&g_vision_finished_LOCK);
//return (void *)result_pipe;
return NULL;
}
The reason why i use a thread is to prevent the vision function from blocking the cyclic task.
Should I simply skip the pthread_join and rely on my g_vision_finished variable?
I am under the impression that I need to join the thread for it to finish completely.
Thanks...
//John