Skip to content

Instantly share code, notes, and snippets.

@vladak
Last active January 3, 2018 09:48
Show Gist options
  • Save vladak/684c87472ae8579bc87dda6bd727013b to your computer and use it in GitHub Desktop.
Save vladak/684c87472ae8579bc87dda6bd727013b to your computer and use it in GitHub Desktop.
lab-threads-2
- signals and threads (*go through the slide first*):
- create process with N threads
- see if sending a signal to the whole process with multiple threads will deliver the signal to
different threads (perform various activities in the threads - I/O, CPU intensive, mix of both, ...)
- define a foo_t type as structure with a reference count and implement 2 macros:
FOO_REHOLD - bumps the refcount
FOO_REFRELE - decrement the refcount and if 0, call foo_free()
that will de-initialize the data structure
- implement negative unit test
- can use mutexes or functions for atomic arithmetic operations
- warm-up: implement pthread_once() (called pthread_myonce()) (*needs mutexes*)
- design pthread_myonce_t/PTHREAD_ONCE_INIT without looking at actual implementation
- write a test case(s) - try leaving out the:
a) init = true
b) mutex_unlock - the test should always complete
- practical coding (*needs mutexes*):
- implement hash table of items (structures) with ref-counting scheme (atomic increment/decrement !)
- hash function - modulo, table has fixed number of buckets, each bucket contains linked list
- strict locking protocol: lock the bucket first, then lock the item
- hash table find, insertion, deletion [traversal]
-
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment