Programming Assignment 3 - Threads - Computer Systems Structure | E C E 329, Assignments of Electrical and Electronics Engineering

Material Type: Assignment; Professor: Birchfield; Class: COMP SYS STRUCT; Subject: ELECTRICAL AND COMPUTER ENGINEERING; University: Clemson University; Term: Fall 2005;

Typology: Assignments

Pre 2010

Uploaded on 07/28/2009

koofers-user-co4
koofers-user-co4 🇺🇸

10 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
ECE 329 Project 1 of 2
Programming Assignment 3 - Threads
Write a C module that implements the simulation of a lightweight thread
package. The code should contain the following interface and functions:
/* initialize the lightweight thread package */
int Thread_Init();
/* create new thread that executes task fptrThread */
int Thread_Create(int (*fptrThread)(),
char *strName, int iStackIndex);
/* O/S pre-empts current thread for the next thread */
int Thread_Yield();
/* thread ceases to run, */
/* if last thread then process calls exit() */
int Thread_Exit();
The function Thread_Init() must be called exactly once before any of the
other two functions.
The function Thread_Create() should only be called from the main thread
(the original thread of your program, not by a thread created with
Thread_Create()).
Each call to Thread_Create() must have a unique value (iStackIndex)
relating to where the corresponding thread’s stack is located.
Upon executing Thread_Init() your program should be transformed into a
system that includes a global Ready queue of threads ready to run with
exactly one thread in the queue - the main thread. Subsequently, the main
thread may start additional threads with Thread_Create(). Any thread can
execute Thread_Yield() to yield the CPU to another thread voluntarily. If
there is more than one thread (main included) desiring execution, a
SIGALRM signal should be used to automatically yield the CPU once every
second.
Your testing code (threads_test.c) should contain at least four and no more
than eight different thread functions (excluding main). These functions
should be written so as to update the display several times a second so that
pf2

Partial preview of the text

Download Programming Assignment 3 - Threads - Computer Systems Structure | E C E 329 and more Assignments Electrical and Electronics Engineering in PDF only on Docsity!

ECE 329 Project 1 of 2

Programming Assignment 3 - Threads

Write a C module that implements the simulation of a lightweight thread package. The code should contain the following interface and functions: /* initialize the lightweight thread package / int Thread_Init(); / create new thread that executes task fptrThread / int Thread_Create(int (fptrThread)(), char strName, int iStackIndex); / O/S pre-empts current thread for the next thread / int Thread_Yield(); / thread ceases to run, / / if last thread then process calls exit() */ int Thread_Exit(); The function Thread_Init() must be called exactly once before any of the other two functions. The function Thread_Create() should only be called from the main thread ( the original thread of your program, not by a thread created with Thread_Create()). Each call to Thread_Create() must have a unique value (iStackIndex) relating to where the corresponding thread’s stack is located. Upon executing Thread_Init() your program should be transformed into a system that includes a global Ready queue of threads ready to run with exactly one thread in the queue - the main thread. Subsequently, the main thread may start additional threads with Thread_Create(). Any thread can execute Thread_Yield() to yield the CPU to another thread voluntarily. If there is more than one thread (main included) desiring execution, a SIGALRM signal should be used to automatically yield the CPU once every second. Your testing code (threads_test.c) should contain at least four and no more than eight different thread functions (excluding main). These functions should be written so as to update the display several times a second so that

ECE 329 Project 2 of 2 the user (and grader) can see the automated context switching and know which thread is being run. Each thread should last at least two time slices (context switches). That is, no thread should complete before the system has a chance to switch it out. The four to eight child functions (threads to create and run) should contain at least one parameter and one local variable which are to be displayed to test for proper stack operation (as in Project 2). The following library calls and system calls are needed for this project: sigsetjmp() - to save a thread's context. siglongjmp() - to restore a thread's context. malloc() - to allocate memory. alloca() - to allocate stack space. signal() - to install a signal handler. alarm() or setitimer() - to generate a reoccurring signal (using ITIMER_REAL). Functions returning an int should return -1 on error and a zero on success. In case of an error, the program should log an error number as previously done in the queues.c package. You must submit the following files: threads3.h and threads3.c: contains the interface definitions and implementation of the threads package. error3.h and error3.c: contains #defines for error codes. queues3.h and queues3.c: contains the interface definitions and implementation of the queue package. t_test.c: contains main and implements and tests the functions created in threads.c. makefile: contains the commands to make your project. Your code should be properly documented and tested.