linux thread synchronization linux thread synchronization multithreading multithreading

linux thread synchronization


Application code should probably use posix thread functions. I assume you have man pages so type

man pthread_mutex_initman pthread_rwlock_initman pthread_spin_init

Read up on them and the functions that operate on them to figure out what you need.

If you're doing kernel mode programming then it's a different story. You'll need to have a feel for what you are doing, how long it takes, and what context it gets called in to have any idea what you need to use.


Thanks to all who answered. We resorted to using gcc atomic operations to synchronize all of our threads. The atomic ops were about 2x slower than setting a value without synchronization, but magnitudes faster than locking a mutex, changeing the value, and then unlocking the mutex (this becomes super slow when you start having threads bang into the locks...) We only use pthread_create, attr, cancel, and kill. We use pthread_kill to signal threads to wake up that we put to sleep. This method is 40x faster than cond_wait. So basicly....use pthreads_mutexes if you have time to waste.


in addtion you should check the nexts books

  • Pthreads Programming: A POSIXStandard for Better Multiprocessing

and

  • Programming with POSIX(R) Threads