Exemple #1
0
/*	int main()
	{
		
		int n;
		int shmid;
		shmid=CreateShm("/home",4,sizeof(UC_ShmMemory));
		p=(UC_ShmMemory*)AttachShm(shmid);
			printf("ccccccccccc\n");
		my_lock_init(p,NULL);
		printf("aaaaaaaaaaaa\n");
		//printf("input:");
	//	scanf("%d",&n);
		//p->CurFileNum=n;
	//	printf("%d\n",p->CurFileNum);
		//sleep(10);
	//	scanf("%d",&n);
	
	while(p->CurFileNum==0)
	my_lock_wait(p);
	//my_lock_wait(p);
	printf("nnnnnnnnnnnn\n");
	printf("%d\n",p->CurFileNum);
		DetachShm(p);
		//DeleteShm(shmid);
		
	}*/
		int main()
	{
		
		UC_ShmMemory *p=NULL;
		int n;
	int shmid;
	//	shmid=CreateShm("/home",4,sizeof(UC_ShmMemory));
	//	p=(UC_ShmMemory*)AttachShm(shmid);
	//	my_lock_init(p,NULL);
	//	printf("input:");
	printf("%d\n",sizeof(UC_ShmMemory));
	init_loop(&p,&shmid,"/home/zhao",26);
printf("%d\n",shmid);
	//	scanf("%d",&n);

		if(!p)
			printf("pppppppppp\n");
//	p->head=n;
	//while(p->head==0)
	//my_lock_wait(p);
	while(1)
	{
	
	my_lock_wait(p);
		printf("%d\n",p->head);
		//	my_lock_release(p);
	if(p->head==-1)
		break;
}		
		destroy_loop(p);
	//	DeleteShm(shmid);

	return 1;
		
	}
Exemple #2
0
void test_lib__common__multithread_c(void)
{
    pthread_t tid;

    main_thread.loop = create_loop();
    main_thread.queue = h2o_multithread_create_queue(main_thread.loop);
    h2o_multithread_register_receiver(main_thread.queue, &main_thread.pong_receiver, on_pong);
    h2o_multithread_register_receiver(main_thread.queue, &main_thread.shutdown_receiver, on_shutdown);
    worker_thread.loop = create_loop();
    worker_thread.queue = h2o_multithread_create_queue(worker_thread.loop);
    h2o_multithread_register_receiver(worker_thread.queue, &worker_thread.ping_receiver, on_ping);

    pthread_create(&tid, NULL, worker_main, NULL);

    /* send first message */
    send_empty_message(&worker_thread.ping_receiver);

    while (!main_thread.received_shutdown) {
#if H2O_USE_LIBUV
        uv_run(main_thread.loop, UV_RUN_ONCE);
#else
        h2o_evloop_run(main_thread.loop, INT32_MAX);
#endif
    }

    pthread_join(tid, NULL);

    h2o_multithread_unregister_receiver(worker_thread.queue, &worker_thread.ping_receiver);
    h2o_multithread_destroy_queue(worker_thread.queue);
    destroy_loop(worker_thread.loop);
    h2o_multithread_unregister_receiver(main_thread.queue, &main_thread.pong_receiver);
    h2o_multithread_unregister_receiver(main_thread.queue, &main_thread.shutdown_receiver);
    h2o_multithread_destroy_queue(main_thread.queue);
    destroy_loop(main_thread.loop);

    ok(1);
}