Skip to content

Instantly share code, notes, and snippets.

@vladak
Last active December 20, 2017 09:16
Show Gist options
  • Save vladak/127cf5fdb1f7860849673644f1b0c5e1 to your computer and use it in GitHub Desktop.
Save vladak/127cf5fdb1f7860849673644f1b0c5e1 to your computer and use it in GitHub Desktop.
- finish the sleep -> join (thread num in argv[1]) task
- write a simple program that creates couple of threads, each doing a number arithm ops
- after random number of the ops, the thread SIGSEGV's, observe the result
- compile with debug flags, see if gdb can display stacks of all threads at the moment of crash
- write simple program with 2 thread types - one sleeping in syscall, another looping and printing to stdout
- create more than 1 thread of each type
- the threads doing syscals can e.g. pick a random file from /etc directory, open it and read it
- each thread will write its own thread ID to stdout once running
- goal: see if the other threads run while another sleeps in syscall
- see if truss/strace can display thread IDs
- need to use strace -f + print the thread ID with gettid()
- thread glob vars
- create N threads
- each thread will have its own "global" variable with dynamically allocated content,
i.e. have to specify a destructor in pthread_key_create() and call free() in it
- see if the destructor is called when thread a) returns b) pthread_exit() c) is cancelled
- check that errno is different in each thread
- pthread_once()
- find good use case, e.g. shared connection in a library (to LDAP server say)
- implement thread pool
- each thread will perform arithmetic operations in a cycle and will exit after random number of iterations
- the main thread will notice the exit and create new thread
- need condvars or signals+pthread_kill() (in both cases use pthread_detach())
- use pthread_cleanup_push() (always call pthread_exit() when the thread is done) to perform the signalling
----
- thread synchro using signals
- block given signal (e.g. USR1) and use sigwait() in producer/consumer
- parallel connect using threads
- cannot use pthread_join() since it waits on specific thread
- really needs condvars
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment