Date of dispatch of assignment: August 24, 2006 Deadline for submission: September 7, 2006
A library maintains the following two tables for books and issuance of books respectively:
Book( Title, Section, AccNo )
Each book can be uniquely identified by its AccNo, which is an integer. The title of the book is a character string
NewTable( Section, AccNo, RollNo )
What is our task? Our task is to write a program that reads the two tables, Book and Issue, into memory and computes the entries of NewTable. We wish to develop this program as a multithreaded program that divides the task of joining the tables into a given even number of threads (the number of threads is an input to the program). The tables, Book and Issue, may be stored as arrays of structures in shared memory. The parent thread reads
How do we collect the results from the participating threads? We want the result (that is NewTable) to appear
Therefore, each thread must compute its assigned subproblem in its own local memory. Next the thread locks (if the variable is free) a global variable (say currIndex, which contains the current index value of the NewTable) to update it and write the computed result in NewTable. While the currIndex is locked, the other threads must busy-wait until it is free.
As an example, suppose thread pthread1 wants to write 5 new entries in the NewTable, when it already contains 7 entries. Therefore, before locking,
currIndex = 7
pthread1 locks the variable and copies 5 new entries from its local memory, into NewTable and before leaving the critical section it updates the variable currIndex. Therefore after unlocking,
currIndex = 12
When all child threads complete the writing, the parent thread prints the contents of NewTable and terminates.
How do we lock a variable? We may use inline assembly code for SPARC Architecture (refer manual and the class lectures). See the usage of the instruction ‘swap’. This instruction is used to swap the values either between a memory location or a register. e.g. “swap [%0], %%o1” swaps the values between the memory location (pointed by register %O) and the register %%o1.
PS: Note that for computing this result, not all attributes of Book and Issue needs to be read into memory. The file name of the C program should be <rollNo>_04.c, it should contain your identity e.g name, roll number, assignment number etc. This file should be available in the subdirectory <roll_number>.oslab e.g. 04cs1048.oslab in your home directory, on or before the last date of report.
|
OS Laboratory Assignment 3 |
Operating Systems Lab: Assignment 4
Computing Join with Threads: |