	#include <stdlib.h>
	#include <string.h>
	#include <stdio.h>
	#include <pthread.h>

	#define THREADS 5
	#define DATA 100

	typedef struct _pthread_arg_t {
		pthread_t thread;
		int *data;
		unsigned int end;
		int max;
	} pthread_arg_t;

	void* pthread_routine(void *arg) {
		pthread_arg_t *info = (pthread_arg_t*) arg;
		int *it = info->data,
			*end = info->data + info->end;

		while (it < end) {
			if (*it > info->max) {
				info->max = *it;
			}
			it++;
		}

		pthread_exit(NULL);
	}

	int main(int argc, char *argv[]) {
		pthread_arg_t threads[THREADS];
		int data[DATA],
			thread = 0,
			limit = 0,
			result = 0;
	
		memset(&threads, 0, sizeof(pthread_arg_t) * THREADS);	
		memset(&data, 0, sizeof(int) * DATA);

		while (limit < DATA) {
			/* you can replace this with randomm number */
			data[limit] = limit;
			limit++;
		}

		limit = DATA/THREADS;

		while (thread < THREADS) {
			threads[thread].data = &data[thread * limit];
			threads[thread].end = limit;
			if (pthread_create(&threads[thread].thread, NULL, pthread_routine, &threads[thread]) != 0) {
				/* do something */
				return 1;
			}
			thread++;
		}

		thread = 0;
		while (thread < THREADS) {
			if (pthread_join(threads[thread].thread, NULL) != 0) {
				/* do something */
				return 1;
			}
			thread++;
		}

		thread = 0;
		result = threads[0].max;
		printf("result:\n");
		while (thread < THREADS) {
			printf("\t%d - %d: %d\n",
				thread * limit,
				thread * limit + limit - 1,
				threads[thread].max);
			if (threads[thread].max > result) {
				result = threads[thread].max;
			}
			thread++;
		}
		printf("max\t%d\n", result);

		return 0;
	}