Esempio n. 1
0
void test_pthread(void)
{
	pthread_t consumer_t = 0;
	pthread_t producer_t = 0;
	Locker *wrlock = locker_pthread_create();
	Locker *nest_lock = locker_pthread_nest_create(wrlock, (ReadSelfId)pthread_self);
#ifdef RW_LOCK
	Locker *rdlock = locker_pthread_create();
	RWLock *rwlock = rwlock_create(wrlock, rdlock);
#endif
	DList *head = NULL;
	
#ifdef RW_LOCK
	head = dlist_create(rwlock);
#else
	head = dlist_create(wrlock);
#endif
	return_if_fail(head != NULL);
	
	pthread_create(&producer_t, NULL, producer_thread, head);
	pthread_create(&consumer_t, NULL, consumer_thread, head);

	pthread_join(consumer_t, NULL);
	pthread_join(producer_t, NULL);
}
Esempio n. 2
0
static void multi_thread_test(void)
{
	pthread_t consumer_tid = 0;
	pthread_t producer_tid = 0;
	DList* dlist = dlist_create(NULL, NULL, locker_pthread_create());
	pthread_create(&producer_tid, NULL, producer, dlist);
	pthread_create(&consumer_tid, NULL, consumer, dlist);

	pthread_join(consumer_tid, NULL);
	pthread_join(producer_tid, NULL);

	return;
}
Esempio n. 3
0
static void multi_thread_test(void)
{
    pthread_t consumer_tid = 0;
    pthread_t producer_tid = 0;
    pthread_t reader_tid = 0;
    Locker* rw_locker = locker_pthread_create();
    Locker* rd_locker = locker_pthread_create();
    DList* dlist = dlist_create(NULL, NULL,
                                rw_locker_create(rw_locker, rd_locker));

    pthread_create(&producer_tid, NULL, producer, dlist);
    pthread_create(&consumer_tid, NULL, consumer, dlist);
    pthread_create(&reader_tid, NULL, reader, dlist);

    pthread_join(consumer_tid, NULL);
    pthread_join(producer_tid, NULL);
    pthread_join(reader_tid, NULL);
    printf("length=%d\n", dlist_length(dlist));
    dlist_destroy(dlist);

    return;
}
Esempio n. 4
0
static void multi_thread_test(void)
{
	pthread_t consumer_tid = 0;
	pthread_t producer_tid = 0;
	Locker* locker = locker_pthread_create();
	Locker* nest_locker = locker_nest_create(locker, (TaskSelfFunc)pthread_self);
	DList* dlist = dlist_create(NULL, NULL, nest_locker);
	pthread_create(&producer_tid, NULL, producer, dlist);
	pthread_create(&consumer_tid, NULL, consumer, dlist);
	printf("===========multi thread test==============\n");
	pthread_join(consumer_tid, NULL);
	pthread_join(producer_tid, NULL);

	return;
}
Esempio n. 5
0
void main()
{
	pthread_t tid1,tid2;
	int err;
	void *tret;

	memset(&L,0,sizeof(dd_link));

	Locker *testLock = locker_pthread_create();	

	InitDDLink(&L);

	printf("***********************Beginning!!!*************************\n");


	while(global_count<5)
	{
		gddlink_update = global_count%2;
		printf("global_count is %d, gddlink_update is %d\n",global_count,gddlink_update);
		global_count++;
		
		err = pthread_create(&tid2, NULL, thread_display, testLock);
		if( 0 != err)
		{
			printf("*****error2*****\n");
		}


		err = pthread_create(&tid1, NULL, thread_insert, testLock);
		if( 0 != err)
		{
			printf("*****error1*****\n");
		}

		sleep(2);
		
	}
	

	printf("***************Final DDLink showing***********************\n");
	DDLinkForeach(&L, DDLinkForeachPrint,print_int);	
	printf("**********ЫЌНу*************\n");

	//DestoryDDLink(&L);
	return;
}
Esempio n. 6
0
Queue* queue_create(DataDestroyFunc data_destroy, void* ctx)
{
	Queue* thiz = (Queue*)malloc(sizeof(Queue));

	if(thiz != NULL)
	{
		Locker* locker = locker_pthread_create();
		Locker* nest_locker = locker_nest_create(locker, (TaskSelfFunc)pthread_self);

		if((thiz->dlist = dlist_create(data_destroy, ctx, nest_locker)) == NULL)
		{
			free(thiz);
			thiz = NULL;
		}
	}

	return thiz;
}