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

Material Type: Assignment; Professor: Ligatti; Class: Operating Systems; Subject: Computer Programming; University: University of South Florida; Term: Fall 2006;

Typology: Assignments

Pre 2010

Uploaded on 09/17/2009

koofers-user-biy-1
koofers-user-biy-1 🇺🇸

5

(1)

10 documents

1 / 1

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

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.