Exemple #1
0
void run_airline(Airline* self, ipc_t conn) {

    mprintf("Dude\n");
    ipcConn = conn;
    me = self;

    register_exit_function(NULL);
    //redirect_signals();

    Vector* threads = bootstrap_planes(self, conn);
    planeThreads = threads;

    listen(threads);

    // If we got here, it means we recieved an end message
    struct Message msg;
    msg.type = MessageTypeEnd;
    broadcast(threads, msg);

    for (size_t i = 0; i < self->numberOfPlanes; i++) {
        struct PlaneThread* t = getFromVector(threads, i);
        pthread_join(t->thread, NULL);
        message_queue_destroy(t->queue);
        free(t);
    }

    destroyVector(threads);
    mprintf("Out of run_airline\n");
}
Exemple #2
0
static void threadpool_destroy() {
	for(int i=0;i<WORKER_THREADS;++i) {
		struct www_op *poison = message_queue_message_alloc_blocking(&worker_queue);
		poison->operation = OP_EXIT;
		message_queue_write(&worker_queue, poison);
	}
	for(int i=0;i<WORKER_THREADS;++i) {
		pthread_join(worker_threads[i], NULL);
	}
	message_queue_destroy(&worker_queue);
}
void message_queue_example(){
	int i, x;
	struct message_queue q;
	int data[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
	
	// initialize.
	message_queue_init(&q);
	
	// add messages.
	for(i=0;i<10;i++){
		message_queue_push(&q, &data[i]);
	}
	
	// get all of the messages.
	while(q.msg_num){
		x = *((int*)message_queue_pop(&q));
		printf("msg: %d\n", x);	
	}
	
	// destroy
	message_queue_destroy(&q);
}