int32_t main(int32_t argc, char* argv[]) { struct xbee *pstrxbee; struct xbee_con *pstrcon; /* Setup Exit */ if(SIG_ERR == signal(SIGINT, my_sighnl)) { fprintf(stderr, "Cannot catch SIGINT!\n"); exit(EXIT_FAILURE); } (void)start_producer(&pstrxbee, &pstrcon); /* Init a Periodic Timer */ (void)start_consumer(DATA_CONSUME_INTERVAL); /* Main Loop */ while(!gs32exitflag) { sleep(5); } (void)stop_consumer(); (void)stop_producer(pstrxbee, pstrcon); return 0; }
int main( int argc, char *argv[] ) { hthread_t prod_tid; hthread_t sort_tid; hthread_t cons_tid; prod_struct prod; sort_struct sort; cons_struct cons; // Setup the structures for the threads DEBUG_PRINTF( "Setting up Structures\n" ); setup_structs( &prod, &sort, &cons ); // Create the producing thread DEBUG_PRINTF( "Creating Producer\n" ); hthread_create( &prod_tid, NULL, prod_thread, (void*)&prod ); // Create the sorting thread DEBUG_PRINTF( "Creating Sorter\n" ); hthread_create( &sort_tid, NULL, sort_thread, (void*)&sort ); // Create the consuming thread DEBUG_PRINTF( "Creating Consumer\n" ); hthread_create( &cons_tid, NULL, cons_thread, (void*)&cons ); // Send the start signal to the producer DEBUG_PRINTF( "Starting Producer\n" ); start_producer( &prod, &sort, &cons ); // Wait for the sorting thread to finish hthread_join( prod_tid, NULL ); // Wait for the sorting thread to finish hthread_join( sort_tid, NULL ); // Wait for the sorting thread to finish hthread_join( cons_tid, NULL ); // Clean up the structures DEBUG_PRINTF( "Cleaning Structures\n" ); destroy_structs( &prod, &sort, &cons ); // Exit the program return 0; }