
CS421 Introduction to Operating Systems
Project 2
Introduction to Multi-Threaded Programming
by Implementing a Memory Management System
1 Objective
To familiarize you with:
Designing and implementing a multi-threaded applications.
Implementing memory management algorithms.
Simulating virtual memory subsystems.
2 Problem Statement
2.1 Introductory Parts: Due October 13th
1. (10 points) Write a program than does the same as part 2 of project 1, except that you are required use
POSIX threads rather than fork’ed processes.
In addition to the main thread, create two additional threads:
one to calculate (but not print) the number of iterations that the sin formula takes. And then make
that result available to the other thread,
the other to calculate and print the number of iterations that the cos formula takes, and receive the
result from the first thread, print it, and compare the two values.
(So the main thread ends up doing very little, other than settings things up, spawning the two threads, and
waiting for them to die.)
Use shared variables as the means of communication between the threads. (Hint: You don’t need pipe.)
Also, since the two threads are started at the same time, and the second needs to know when the data from
the first is available, some form of synchronization is required. You may do this in one of two ways (your
choice):
Use a variable as a flag, and have the second thread wait in a tight loop, until the flag indicates that the
data is ready. (Note: this is a very bad way to solve a synchronization problem. It is being permitted
only in this one case of this part of the project.)
Use the pthread mutex t mutual exclusion calls. (For example: have the main thread lock the
mutex before it calls the two threads, have the first thread unlock it when the data is ready, and have
the second thread lock it as it starts.)
Note: You must start both threads before you wait for either of them. You will lose points if you call
pthread_join on the first thread before you start the second thread running.
1