Пример #1
0
int main(void)
{
    pthread_mutex_init(&mutex, NULL);
    pthread_cond_init(&full, NULL);
    pthread_cond_init(&empty, NULL);
    init_queue(&Q);

    pthread_create()

    pthread_cond_destory(&empty);
    pthread_cond_destory(&full);
    pthread_mutex_destory(&mutex);
    return 0;
}
int main(int argc, char const *argv[])
{
	pthread_t pro, con;
	pthread_mutex_init(&the_mutex, 0);
	pthread_cond_init(&condc, 0);
	pthread_cond_init(&condp, 0);
	pthread_create(&con, 0, consumer, 0);
	pthread_create(&pro, 0, producer, 0);
	pthread_join(pro, 0);
	pthread_join(con, 0);
	pthread_cond_destory(&condc);
	pthread_cond_destory(&condp);
	pthread_mutex_destory(&the_mutex);
	return 0;
}
// parameter strategy is currently unavailable...
// pass NULL instead..
void init_flow_balance(void* s) {
	pthread_mutex_init(&pool_lock, NULL);
	struct tunet_connection* ptc = NULL;
	int idx = 0;
	while (! fb_stop) {
		//lock
		pthread_mutext_lock(&pool_lock);
		idx %= tc_cnt;
		ptc = tc_pool[idx];
		idx += 1;
		tunet_login(ptc, 1);	
		//unlock
		pthread_mutext_unlock(&pool_lock);
		sleep(3600);
		//lock
		pthread_mutext_lock(&pool_lock);
		tunet_logout(ptc);
		pthread_mutext_unlock(&pool_lock);
		//unlock
	}
	pthread_mutex_destory(&pool_lock);
}
void destroy_queue(pQueue *q)
{
	pthread_mutex_destory(&(*q)->m_critial);
	pthread_cond_destory(&(*q)->no_full);
	pthread_cond_destory(&(*q)->no_empty);
}