24-Thread-Package-Docs

24-Thread-Package-Docs - CS107 Spring 2007 Handout 24 May...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
CS107 Handout 24 Spring 2007 May 4, 2007 CS107 Thread Package Documentation Thread package and handout was written by Julie Zelenski ( zelenski@cs.stanford.edu ) Threads We will do our concurrent programming work using a platform-specific thread package based on the Solaris threads facility. Solaris is running on most of the campus Sparcstations, so you have many machines to choose from ( elaine , tree, junior ). Note that unlike the earlier straight C programming assignments, you won't be able write and debug it on a Mac/PC and just port it to UNIX as the last step because the thread library only runs on Solaris. Our simple interface is defined in thread_107.h which itself is built on the primitives in Solaris thread.h . Editorial Comment This is a classic standards problem: there is nothing especially difficult about defining a standard threads package. There are many, many out there, and they all do pretty much the same thing in similar by not identical ways. Sadly, without a standard interface, there is no way you can write code that is portable across all machines. This is exactly the situation standards committees are supposed to solve, but it is a politically difficult one given there is so much inertia invested in all the existing yet slightly incompatible interfaces. The code for our package resides in the /usr/class/cs107/other/thread_library directory. The source files are thread_107.c and thread_107.h . The thread package has been compiled and saved as a library in the class directory. You need to include the header file thread_107.h to see the prototypes and must link with the libthread_107.a library to bring in the necessary code. You need not be concerned with the library source, although if you are interested in how some of the routines are implemented, feel free to browse through it. We will provide a Makefile which puts cs107/include in the include path and cs107/lib in the link path as well as linking with the necessary libraries. void InitThreadPackage(bool traceFlag); This procedure initializes the thread package. Call it once (and only once) at the beginning of your main program before you call any other functions from the thread package. The Boolean traceFlag controls whether debug tracing output is produced on thread exit and semaphore wait and signal activity. Turning on tracing may be useful during debugging, although the output can be prodigious.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2 Thread functions void ThreadNew(const char *debugName, void (*func)(), int nArg, . ..); This procedure creates a new thread to execute the function func . ThreadNew is a variable-argument function, somewhat like printf , that allows you to specify different numbers and types of arguments depending on what values you need to pass to the new thread’s starting function.
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 5

24-Thread-Package-Docs - CS107 Spring 2007 Handout 24 May...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online