void assign(int pri) { int i; for (i = 0; i < 3; i++) printf("in assign(1): %d\n", i); t_yield(); for (i = 10; i < 13; i++) printf("in assign(2): %d\n", i); t_yield(); for (i = 20; i < 23; i++) printf("in assign(3): %d\n", i); }
/* Main thread */ void usb_thread (void) { for (;;) { bcond_wait(&usb_active); t_yield(); int16_t c; while ((c = CDC_Device_ReceiveByte(&VirtualSerial_CDC_Interface)) > 0) stream_put(&cdc_instr, c); t_yield(); while ( ! stream_empty(&cdc_outstr)) CDC_Device_SendByte(&VirtualSerial_CDC_Interface, stream_get(&cdc_outstr)); CDC_Device_USBTask(&VirtualSerial_CDC_Interface); USB_USBTask(); } }
int main(void) { CLKPR = (1<<7); CLKPR = 0; /* Disable watchdog timer */ MCUSR = 0; wdt_disable(); /* Start the multi-threading kernel */ init_kernel(STACK_MAIN); /* Timer */ TCCR2B = 0x03; /* Pre-scaler for timer0 */ TCCR2A = 1<<WGM21; /* CTC mode */ TIMSK2 = 1<<OCIE2A; /* Interrupt on compare match */ OCR2A = (SCALED_F_CPU / 32 / 2400) - 1; TRACE_INIT; sei(); t_stackErrorHandler(stackOverflow); fbuf_errorHandler(bufferOverflow); reset_params(); /* HDLC and AFSK setup */ mon_init(&cdc_outstr); adf7021_init(); inframes = hdlc_init_decoder( afsk_init_decoder() ); outframes = hdlc_init_encoder( afsk_init_encoder() ); digipeater_init(); /* Activate digipeater in ui thread */ /* USB */ usb_init(); THREAD_START(usbSerListener, STACK_USBLISTENER); ui_init(); /* GPS and tracking */ gps_init(&cdc_outstr); tracker_init(); TRACE(1); while(1) { lbeep(); if (t_is_idle()) { /* Enter idle mode or sleep mode here */ powerdown_handler(); sleep_mode(); } else t_yield(); } }
int main(int argc, char **argv) { t_init(); t_create(assign, 1, 1); printf("in main(): 0\n"); t_yield(); printf("in main(): 1\n"); t_yield(); printf("in main(): 2\n"); t_yield(); printf("done...\n"); return (0); }
void PROCESSOR::message_idle_loop() { int message_id,source; while(!scorpio_ending) { while(IProbe(source,message_id)) { g_message_id = message_id; g_source_id = source; /*Message thread handles all messages except SPLIT and GOROOT*/ if(message_id == SPLIT || message_id == GOROOT) { message_available = 1; while(message_available) t_yield(); } else { handle_message(source,message_id); } } offer_help(); t_yield(); } }
void function(int thr_id) { int i, j; for (i = j = 0; i < 3; i++, j++) { printf("this is thread %d [%d]...\n", thr_id, j); t_yield(); } printf("Thread %d is done...\n", thr_id); t_terminate(); }
void sem_signal(sem_t *sp) { while(sem_try_lock(sp) != 0); int yield = 0; ((sem*)sp)->value++; if ( ((sem*)sp)->value <= 0 ) { assert(!is_list_empty(&((sem*)sp)->waiters)); sem_unblock(sp); yield = 1; } sem_unlock(sp); if (yield == 1) t_yield(); }
int main(void) { int i; t_init(); t_create(producer, 1, 1); t_create(producer, 3, 1); t_create(consumer, 2, 1); t_yield(); t_shutdown(); return 0; }
int main(void) { int i; t_init(); t_create(function, 1, 1); printf("This is main(1)...\n"); t_create(function, 2, 1); printf("This is main(2)...\n"); t_create(function, 3, 1); for (i = 0; i < 4; i++) { printf("This is main(3)[%d]...\n", i); t_yield(); } printf("Begin shutdown...\n"); t_shutdown(); printf("Done with shutdown...\n"); return 0; }
/* * Catch a signal, yield to the next thread */ void signal_handler(int x){ signal(SIGALRM, signal_handler); t_yield(); }