Docsity

Multithreaded Program - Assignment - Fall 2006 | COP 4600, Assignments of Operating Systems

Toggle sidebar
bg1
COP 4600, Fall 2006 Extra Credit Assignment
Due: Monday, September 18, 2006, at the beginning of class.
Assignment description:
Consider the multithreaded program below:
#include <pthread.h>
#include <stdio.h>
#define N 2
void *printSi(void *threadid) {
printf("%d: Si\n", threadid);
pthread_exit(0);
}
int main (int argc, char *argv[]) {
pthread_t threads[N];
pthread_attr_t attr[N];
int t;
for(t=0; t<N; t++){
printf("Creating thread %d\n", t);
pthread_attr_init(&attr[t]);
pthread_create(&threads[t], &attr[t], printSi, (void *)t);
}
pthread_exit(0);
}
When N is 2, as above, there are three possible outputs from running this program:
Creating thread 0 Creating thread 0 Creating thread 0
0: Si Creating thread 1 Creating thread 1
Creating thread 1 0: Si 1: Si
1: Si 1: Si 0: Si
Question: In general, how many possible outputs are there for a given N? In other
words, what is the function F(N) that returns the number of possible outputs for any
positive integer N? (F(1) should equal 1, F(2) should equal 3, etc.)
Simplify your answer as much as possible.

Partial preview of the text

Download Multithreaded Program - Assignment - Fall 2006 | COP 4600 and more Assignments Operating Systems in PDF only on Docsity!

COP 4600, Fall 2006 Extra Credit Assignment

Due: Monday, September 18, 2006, at the beginning of class. Assignment description: Consider the multithreaded program below: #include <pthread.h> #include <stdio.h> #define N 2 void *printSi(void *threadid) { printf("%d: Si\n", threadid); pthread_exit(0); } int main (int argc, char *argv[]) { pthread_t threads[N]; pthread_attr_t attr[N]; int t; for(t=0; t<N; t++){ printf("Creating thread %d\n", t); pthread_attr_init(&attr[t]); pthread_create(&threads[t], &attr[t], printSi, (void *)t); } pthread_exit(0); } When N is 2, as above, there are three possible outputs from running this program: Creating thread 0 Creating thread 0 Creating thread 0 0: Si Creating thread 1 Creating thread 1 Creating thread 1 0: Si 1: Si 1: Si 1: Si 0: Si Question: In general, how many possible outputs are there for a given N? In other words, what is the function F(N) that returns the number of possible outputs for any positive integer N? (F(1) should equal 1, F(2) should equal 3, etc.) Simplify your answer as much as possible.