Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <pthread.h>
- #define THREAD_COUNT 8
- #define WORK 25000
- void* stress(void* x)
- {
- int j;
- for(j = 0; j < WORK; ++j){
- int array[100][100];
- int i, k;
- for (i = 0; i < 100; ++i) {
- for (k = 0 ; k < 100; ++k) { array[i][k] += i + k * rand();}
- }
- }
- return NULL;
- }
- int main()
- {
- pthread_t thread_ids[THREAD_COUNT];
- int thread_args[THREAD_COUNT];
- int i;
- // Spawn the threads
- for (i = 0; i < THREAD_COUNT; ++i)
- {
- thread_args[i] = i;
- pthread_create(
- &thread_ids[i] // Thread ID
- ,NULL // Thread Attributes (NULL is fine)
- ,stress // Function thread will call
- ,(void*) &thread_args[i] // Arguments passed to function
- );
- }
- // Wait for threads to finish
- for (i = 0; i < THREAD_COUNT; ++i)
- {
- pthread_join(thread_ids[i], NULL);
- }
- printf("done");
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement