

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Material Type: Notes; Professor: Corner; Class: Operating Systems; Subject: Computer Science; University: University of Massachusetts - Amherst; Term: Spring 2009;
Typology: Study notes
1 / 3
This page cannot be seen from the preview
Don't miss anything!


CMPSCI 377 Operating Systems Spring 2009
Lecturer: Mark Corner Scribes: Bruno Silva,Jim Partan
As with Lectures 1 and 2, most of the details of the C++ portion of this lecture is in the 377 Student Guide to C++, which has links on the course website. Here are a few additional notes.
The STL details are described in many places online (see the CS377 webpage for some links), and there’s a very quick introduction in Section 14 of the 377 Student Guide to C++. Here are just a few additional notes:
Function calls in C++ pass by value, making a copy of the argument. If you need to modify the argument, or if making a copy of a large object would be consume too much time and memory, then passing by reference (a pointer) is often preferable.
Similarly, many of the STL methods (e.g. insert(), etc) are set up to pass potentially large objects by value, rather than by reference. For this reason, one might want to create objects composed of pointers, rather than objects. For example, if you wanted a queue-of-queues, with larger datasets, you’d probably want to use a queue-of-pointers-to-queues instead, such as
queue<queue
rather than
queue<queue
(note the space in the second declaration, because >> is a C++ operator).
As a couple of very quick STL examples, consider
queue<int *> myqueue; int *ptr = new int; myqueue.push(ptr);
and
map<int,char> mymap; mymap[10]=’a’;
4-2 Lecture 4: February 5
The second example is a map indexed by ints, storing chars.
Command-line parameters are passed into programs using the arguments of main(). Here’s a quick example, for a program called by typing “progname file.txt 1 2.7”:
#include
int main(int argc, char *argv[]) { char *progname, *filename; int value1; float value2;
if (argc != 4) { cerr << "usage: " << argv[0] << " file.txt int float" << endl; exit(1); }
progname = argv[0]; // argv[0] is the executable’s name itself filename = argv[1]; value1 = atoi(argv[2]); // convert C-string to int with atoi() value2 = atof(argv[3]); // convert C-string to float with atof()
cout << progname << " " << filename << " " << value1 << " " << value2 <<endl; exit(0); }
Processes and threads each have their place in multi-programming, generally to hide latency and to maximize CPU utilization.
With the continuing spread of multi-core processors in personal computers, threads are becoming more and more important every day. There are now threads in almost every type of application, including client ap- plications, not just server applications. Soon, there are likely to be multi-core processors even on cellphones, and there will be threaded applications on cellphones.
These multiple cores make it possible to run several different lines of processing at the same time, allowing the computer to run much faster than usual; because of this, however, programmers must now explicitly make use of multi-threaded programming. Unfortunately, parallel programming is very confusing and error prone.
In general, parallel programming can be implemented either by using several concurrent processes, or by using threads. While processes have each their own address space (separate program counters, heaps, stacks, etc), threads share their address spaces; the programmer can use either of these to obtain concurrency.