All pastes #911367 Raw Edit

Stuff

public c v1 · immutable
·published 2008-02-20 17:39 UTC
rendered paste body
#include <stdlib.h>#include <stdio.h>#include <pthread.h>#include "wqueue.h"wqueue_t *wq;void print_me(void *data) {	printf(":: %s\n", (char*)data);}void sum(void *data) {	int *a = (int*)data;	char *buffer = malloc(10*sizeof(char));	sprintf(buffer, "%i", a[0]+a[1]);	printf("Inserting subjobs...\n");	wqueue_ts_insert(wq, -1, &print_me, buffer);	wqueue_ts_insert(wq, -1, &free, buffer);}int main() {	wq = malloc(sizeof(wqueue_t));	if(wq==NULL)		return 1;	wq->first = NULL;	wq->last = NULL;	pthread_mutex_init(&wq->condition_mutex, NULL);	int p[2] = {5, 10};	int q[2] = {50, 100};	wqueue_ts_insert(wq, 3, (work_f)print_me, "Thread A. 3");	wqueue_ts_insert(wq, 2, (work_f)print_me, "Thread B. 2");	wqueue_ts_insert(wq, 3, (work_f)print_me, "Thread C. 3");	wqueue_ts_insert(wq, 4, (work_f)print_me, "Thread D. 4");	wqueue_ts_insert(wq, 3, (work_f)print_me, "Thread E. 3");	wqueue_ts_insert(wq, 2, (work_f)print_me, "Thread F. 2");	wqueue_ts_insert(wq, 1, (work_f)print_me, "Thread G. 1");	wqueue_ts_insert(wq, 3, (work_f)print_me, "Thread H. 3");	wqueue_ts_insert(wq, 1, (work_f)sum, q);	wqueue_ts_insert(wq, 4, (work_f)sum, p);	wqueue_thread_pool(wq, 3);	return 0;}