solaris device driver 2
"writing device driver" study.1. Multithreading
1) storage classes
- Automatic(stack) data. Every thread has private stack. No need for the driver to lock automatic data.
- Global static data. can be shared by any number of threads in the driver. should be locked at times.
- Kernel heap data. Any number of threads in the driver can share kernel heap data, such as data allocated by kmem_alloc(9F). The driver needs to protect shared data at all times.
2) locks
a) Mutual-extension locks(Mutex). Mutexes provide a way to allow only one thread at a time access to that data.
b) reader/writer locks. Many threads can hold the lock simultaneously for reading, but only one thread can hold the lock for writing.
c) Semaphores.
3) Thread Synchronization
a) Condition variables. The usual use of condition variables is to check a condition (forexample, device state, data structure reference count,etc.) while holding a mutex which keeps otherthreadsfrom changingthecondition. The cv_wait(9F) function releases the mutex before blocking the thread and reacquires the mutex before returning.
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u1/38597/showart_301076.html
页:
[1]