Part I Application Programming Interface
2. STREAMS Application-Level Components
3. STREAMS Application-Level Mechanisms
4. Application Access to the STREAMS Driver and Module Interfaces
7. STREAMS Framework - Kernel Level
8. STREAMS Kernel-Level Mechanisms
11. Configuring STREAMS Drivers and Modules
Multithreaded (MT) STREAMS Overview
Routines Used Inside a Perimeter
Asynchronous Callback Functions
Unloading a Module that Uses esballoc
MT SAFE Modules Using Explicit Locks
Sample Multithreaded Device Driver Using a Per Module Inner Perimeter
Sample Multithreaded Module With Outer Perimeter
14. Debugging STREAMS-based Applications
B. Kernel Utility Interface Summary
A module or a driver can be either MT SAFE or MT UNSAFE. A module or driver is MT SAFE when its data values are correct regardless of the order that multiple threads access and modify the data. For MT SAFE mode, use MT STREAMS perimeters to restrict the concurrency in a module or driver to:
Per-module single threading
Per queue-pair single threading
Per queue single threading
Per queue or per queue-pair single threading of the put and service procedures with per module single threading of the open and close routines
Unrestricted concurrency in the put and service procedures with the ability to restrict the concurrency when handling messages that modify data
Completely unrestricted concurrency
To configure a module as being MT SAFE, use the f_flag field in fmodsw(9S).
The easiest method is to initially implement your module and configure it to be per-module single threaded, and increase the level of concurrency as needed. Sample Multithreaded Device Driver Using a Per Module Inner Perimeter provides a complete example of using a per-module perimeter, and Sample Multithreaded Module With Outer Perimeter provides a complete example with a higher level of concurrency.
MT SAFE modules can use different MT STREAMS perimeters to restrict the concurrency in the module to a concurrency that is natural given the data structures that the module contains, thereby removing the need for module private locks (see MT STREAMS Perimeters for information on perimeters). A module that requires unrestricted concurrency can be configured to have no perimeters. Such modules have to use explicit locking primitives to protect their data structures. While such modules can exploit the maximum level of concurrency allowed by the underlying hardware platform, they are more complex to develop and support. See MT SAFE Modules Using Explicit Locks.
Independent of the perimeters, there will be at most one thread allowed within any given queue's service procedure.
Your MT SAFE modules should use perimeters and avoid using module private locks (mutex, condition variables, readers/writer, or semaphore). Should you opt to use module private locks, you need to read MT SAFE Modules Using Explicit Locks along with this section.
Note - MT UNSAFE mode for STREAMS modules was temporarily supported as an aid in porting SVR4 modules; however, MT UNSAFE is not supported after SVR4. Beginning with the release of the Solaris 7 operating environment, no MT UNSAFE module or driver has been supported.
Note - Upper and lower multiplexors share the same perimeter type and concurrency level.
To configure a driver as being MT SAFE, initialize the cb_ops(9S) and dev_ops(9S) data structures. This code must be in the header section of your module. For more information, see Example 12-1, and dev_ops(9S).
The driver is configured to be MT SAFE by setting the cb_flag to D_MP. It also specifies any MT STREAMS perimeters by setting flags in the cb_flag field. (See mt-streams(9F).)