טסטים למאגר החוטים בלבד:
מיין1, מיין2.
מיין2 תדפיס
done
בסוף.
מיין 1 לא דטרמיניסטי וידפיס כנראה 290 ומשהו מספרים החל מ-1.

טסט לדיספצ'ר:
main1 and main2 are for the threadpool alone.
Hannoy is for the dispatcher.

Hannoy output:
cat /tmp/outputpipe_hw3 | wc -l
will give 220.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Technion References" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/reference-technion?hl=en
-~----------~----~----~----~------~----~------~--~---

Attachment: Hannoy
Description: Binary data

/*
* adds 400 tasks while removing some of your threads in the middle and then adds 
* new threads again.
* At the end it removes all threads and adds a task and then attempts to destroy the
* thread pool.
* enjoy
*/

#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <unistd.h>
#include "thread_pool.h"
#include "queue.h"

typedef struct info{
	int a;
}info;


void* fun(void *a, void *b){
	int i = 0 , j = 0 , k = 0, res = 0;
	sleep(1);
	for(i = 0 ; i < 3 ; i++){
		for(j = 0 ; j < 175 ; j++)
			for(k = 0 ; k < 91 ; k++){
				res += i*j*k + 13;
			}
	}
	free(b);
	printf("my pid is %u\n", (int)pthread_self());
	printf("I got %d\n", res);
	return NULL;
}

int main(){
	int i = 0;
	thread_pool_t pool = thread_pool_create(fun, NULL, 9);
	if(pool == NULL){
		printf("you fail at thread_pool_create.\n");
		return 1;
	}
	for(i = 0 ; i < 300 ; i++){
		int *task = (int*)malloc(sizeof(int));
		*task = i;
		thread_pool_add_task(pool, task);
		if((i % 17) == 0){
			thread_pool_remove_threads(pool, 5);
			thread_pool_add_threads(pool, 5);
		}
	}
	/* remaining with 0 threads */
	thread_pool_remove_threads(pool, 9);
	int *task = (int*)malloc(sizeof(int));
	thread_pool_add_task(pool, task);
	thread_pool_destroy(pool);

	return 0;
}
	
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <unistd.h>
#include "thread_pool.h"
#include "queue.h"

typedef struct info{
	int a;
}info;


void* fun(void *a, void *b){
	int i = 0 , j = 0 , k = 0, res = 0;
	sleep(1);
	for(i = 0 ; i < 3 ; i++){
		for(j = 0 ; j < 175 ; j++)
			for(k = 0 ; k < 91 ; k++){
				res += i*j*k + 13;
			}
	}
	free(b);
	printf("my pid is %u\n", (int)pthread_self());
	printf("I got %d\n", res);
	return NULL;
}

int main(){
	int i = 0;
	thread_pool_t pool = thread_pool_create(fun, NULL, 9);
	if(pool == NULL){
		printf("you fail at thread_pool_create.\n");
		return 1;
	}
	for(i = 0 ; i < 147 ; i++){
		int *task = (int*)malloc(sizeof(int));
		*task = i;
		thread_pool_add_task(pool, task);
	}
	thread_pool_ternimate(pool);
	printf("done\n");

	return 0;
}
	

לענות