CS520
Spring 2017
Laboratory 8
Friday March 31
The lab must be submitted prior to noon on Sunday April 2.


Update your symbol table facility from Lab 5 to support concurrent (multithreaded) access to created tables.

Complete this assignment by doing the following steps in the order given:

  1. Copy symtab.h from ~cs520/public/lab8. Read it carefully!

  2. A second parameter has been added to the symtabCreate function to indicate the number of POSIX mutexes to use to protect access to the table. Modify your code to include this parameter. This parameter needs to be at least 1, and should be stored in the control struct for the new table. Also, you need to malloc space for an array of the mutexes and store the base address of that array in the control struct. Finally, scale the size hint provided as the first parameter so that the size of the table that is created is the closest even multiple of the number of mutexes.

  3. A third parameter has been added to the symtabCreate function to indicate whether thin locks should be used instead of POSIX mutexes to protect access to the table. Modify your code to include this parameter. This parameter should be stored in the control struct for the new table. However, for this lab, if the third parameter is not 0, print an error message to stderr and exit the program.

  4. The symtabInstall function has been replaced by the symtabUpdate function. With the old interface, users would often follow a symtabLookup call with a call to symtabInstall, in order to modify the data associated with a symbol already installed in the table. With the new interface, this can now be done with one call to symtabUpdate. The trick is that the caller now passes a callback function to symtabUpdate, which is called with the old data pointer for the given symbol. The user can then examine and modify the old data and return an updated data pointer back to symtabUpdate as the callback function's return value. symtabUpdate then installs the updated data pointer with the symbol in the table. symtabUpdate takes a fourth argument that is passed to the callback function as its second argument. Modify your code for symtabInstall to implement symtabUpdate.

  5. Groups of hash buckets will be assigned to mutexes by taking the hash index of the bucket modulo the number of mutexes specified when the table was created. When symtabLookup or symtabUpdate are called for a table, lock the mutex for the symbol's bucket upon entry to the function and unlock that mutex right before exit of the function.

  6. Test your code using the main.c in ~cs520/public/lab8. This is a concurrent version of the program we used to test Lab 5. Use valgrind to be sure that all of memory is reclaimed. And use helgrind to be sure there are no concurrency errors. Be sure to vary the number of files to be processed in order to vary the number of threads that are accessing the table. Also vary the number of mutexes used to protect the table.

Points will be awarded in the following way: To turn in this laboratory, type:
% ~cs520/bin/submit lab8 symtab.c

Submissions can be checked by typing:

% ~cs520/bin/scheck lab8

Remember that there are no late submissions of labs. Submit what you have prior to noon on Sunday April 2.


Last modified on March 21, 2017.

Comments and questions should be directed to pjh@cs.unh.edu