void semaphore_cinema_end(int i) /* i:影片编号从0到N-1 */ { down(&mutex); /* 进入临界区 */ people--; cprintf(""No.%d movie_sema quit,remain people num: %d \n"",i,people); if(people==0) cinema=-1; semaphore_test(left); semaphore_test(right); /* 看一下其他影片可否播放 */ up(&mutex); /* 离开临界区 */ }
int main(int argc, char* argv[]) { locker_test(); atomic_test(); spinlock_test(); event_test(); #if !defined(OS_MAC) semaphore_test(); #endif stack_test(); #if defined(OS_WINDOWS) // rtsp_header_range_test(); rtsp_header_session_test(); rtsp_header_rtp_info_test(); rtsp_header_transport_test(); sdp_test(); sdp_a_fmtp_test(); sdp_a_rtpmap_test(); url_test(); unicode_test(); utf8codec_test(); thread_pool_test(); ip_route_test(); //aio_socket_test(); //systimer_test(); system("pause"); #endif return 0; }
int mutex_test(void) { pj_pool_t *pool; int rc; pool = pj_pool_create(mem, "", 4000, 4000, NULL); rc = simple_mutex_test(pool); if (rc != 0) return rc; rc = recursive_mutex_test(pool); if (rc != 0) return rc; #if PJ_HAS_SEMAPHORE rc = semaphore_test(pool); if (rc != 0) return rc; #endif pj_pool_release(pool); return 0; }
int main(int argc, char ** argv) { /* Calibrate the the uDelay loop */ cm3_udelay_calibrate(); /* Initialize the stdin, stdout and stderr */ stdio_init(); /* Print a useful information message */ printf("\n"); printf("---------------------------------------------------------\n"); printf(" ThinkOS - Semaphore example\n"); printf("---------------------------------------------------------\n"); printf("\n"); /* Initialize the ThinkOS kernel */ thinkos_init(THINKOS_OPT_PRIORITY(0) | THINKOS_OPT_ID(0)); /* Run the test */ semaphore_test(); thinkos_sleep(10000); return 0; }
int thread_tests(void) { mutex_test(); semaphore_test(); event_test(); atomic_test(); thread_sleep(200); context_switch_test(); preempt_test(); return 0; }
void semaphore_movie_play(int i) { down(&mutex); semaphore_test(i); int ifwait=0; if (i!=cinema) ifwait=1; wait[i]+=ifwait; //cprintf(""testing %d %d %d\n"",cinema,i,mov[i].value); up(&mutex); down(&mov[i]); down(&mutex); wait[i]-=ifwait; people++; cinema=i; cprintf(""No.%d movie_sema is playing,remain people num:%d \n"",i,people); /*电影放映*/ //cprintf(""testING %d %d %d %d\n"",cinema,i,mov[i].value,wait[i]); if (wait[i]!=0) up(&mov[i]); up(&mutex); //if (bf==people) down(&mov[i]); }
int main(int argc, char* argv[]) { #if defined(OS_LINUX) struct sigaction sa; sa.sa_handler = SIG_IGN; sigaction(SIGCHLD, &sa, 0); sigaction(SIGPIPE, &sa, 0); #endif heap_test(); rbtree_test(); timer_test(); socket_test(); locker_test(); atomic_test(); #if defined(ATOMIC_TEST) atomic_test2(); #endif spinlock_test(); event_test(); #if !defined(OS_MAC) semaphore_test(); #endif onetime_test(); bits_test(); stack_test(); time64_test(); base64_test(); bitmap_test(); hweight_test(); ring_buffer_test(); uri_parse_test(); #if defined(HTTP_TEST) http_test(); #endif thread_pool_test(); task_queue_test(); ip_route_test(); aio_socket_test_cancel(); aio_socket_test(); aio_socket_test2(); aio_socket_test3(); aio_socket_test4(); #if defined(OS_WINDOWS) unicode_test(); utf8codec_test(); systimer_test(); system("pause"); #endif return 0; }