📄 streams.doc13.html
字号:
</td><td colspan=1 rowspan=1></td></tr><tr><td colspan="20"><hr class="tablerule"></td></tr><tr valign="middle"><td colspan="20"></td></tr></table></p> <div class="frame"><h4 class="EntityTitle"><a name="82347" class="autotag"><font face="Helvetica, sans-serif" size="-1" class="sans">Figure 13. Component Instances and Queues</font></a></h4><div class="CellBody"><a name="92257" class="autotag"> </a><img class="figure" border="0" alt="" src="images/streams.doc.anc.gif"></div></div> </p></dd></dl></dd></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H4"><i><a name="71812" class="autotag"><b>SQLVL_QUEUE</b></a></i></h4></font><dl class="margin"><dd><dl class="margin"><dd><p class="Body"><a name="71813" class="autotag"> </a>This is the least restrictive synchronization level. Separate threads of execution can run concurrently in the read-side and write-side queues of a component instance. In <a href="streams.doc13.html#87215"><i class="title">Figure 13</i></a>, if Component A has <b>SQLVL_QUEUE</b> synchronization, four separate threads, one in each queue--A1, A2, A3, and A4--can be executing simultaneously; no two threads are permitted to execute simultaneously in any one queue of Component A. </p></dd></dl></dd></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H4"><i><a name="71818" class="autotag"><b>SQLVL_QUEUEPAIR </b></a></i></h4></font><dl class="margin"><dd><dl class="margin"><dd><p class="Body"><a name="71819" class="autotag"> </a>Only one thread of execution is permitted in either the read-side or write-side queue of a component instance at a time. However, multiple instances may each have a separate concurrent thread of execution. In <a href="streams.doc13.html#87215"><i class="title">Figure 13</i></a>, if Component A has <b>SQLVL_QUEUEPAIR</b> synchronization, two separate threads, one in queue A1 or A2, and another in A3 or A4, could be executing simultaneously. If a thread is executing in queue A1, no thread can access A2 until the thread in A1 exits; similarly for queues A3 and A4. This synchronization level should be selected when configuring STREAMS components that do not share state data outside of the component instance. Components that meet this criteria can, and should, also run with <b>SQLVL_QUEUE</b>. </p><p class="Body"><a name="78469" class="autotag"> </a>Notice that both <b>SQLVL_QUEUE</b> and <b>SQLVL_QUEUEPAIR</b> permit separate simultaneous threads of execution in different instances of the same component, even different instances in the same stream. The two levels differ in that <b>SQLVL_QUEUE</b> permits a distinct active thread in each of the read-side and write-side queues of the component (both queue A1 and A2 at the same time), whereas <b>SQLVL_QUEUEPAIR</b> permits an active thread in either the read-side or write-side queue, but not both at the same time (queue A1 or A2, but not both at the same time). </p></dd></dl></dd></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H4"><i><a name="71823" class="autotag"><b>SQLVL_MODULE</b></a></i></h4></font><dl class="margin"><dd><dl class="margin"><dd><p class="Body"><a name="71824" class="autotag"> </a>This level most closely approximates single-thread STREAMS execution. Only a single active thread is permitted in any queue of any instance of the component. In <a href="streams.doc13.html#87215"><i class="title">Figure 13</i></a>, if Component A has <b>SQLVL_MODULE</b> synchronization, only one thread can execute in any queue--A1, A2, A3, or A4--at any one time. </p><p class="Body"><a name="78336" class="autotag"> </a>Designate <b>SQLVL_MODULE </b>synchronization if you are porting STREAMS components of the following types:</p></dd></dl><dl class="margin"><dd><p class="listspace"><ul class="Bullet" type="disc"><li><a name="71828" class="autotag"> </a>STREAMS components having instances that share significant amounts of volatile data between themselves. When you configure components with <b>SQLVL_MODULE</b>, a bottleneck can occur when traffic flow is heavy across multiple instances (because only one queue is executing at a time). However, there are many cases of components handling very low traffic; the effort to rewrite those components to avoid data sharing may not be worthwhile. </li></ul></p><p class="listspace"><ul class="Bullet" type="disc"><li><a name="71829" class="autotag"> </a>STREAMS components whose code architecture is unknown. You can safely configure the component with <b>SQLVL_MODULE</b> synchronization and modify it later with a finer level of synchronization, if you decide that the effort to understand and rewrite the code is worthwhile. Using <b>SQLVL_MODULE</b> may result in the same kind of traffic bottleneck as above, a trade-off faced in lieu of rewriting the code.</li></ul></p></dd></dl></dd></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H4"><i><a name="71830" class="autotag"><b>SQLVL_GLOBAL</b></a></i></h4></font><dl class="margin"><dd><dl class="margin"><dd><p class="Body"><a name="89356" class="autotag"> </a>This is the most restrictive (and most rarely used) level of synchronization. It is used by a family of cooperating components to ensure that only a single queue in any instance of any component in the family is being executed at any one time. In <a href="streams.doc13.html#87215"><i class="title">Figure 13</i></a>, if A and B are members of the same family of cooperating components and both are installed with <b>SQLVL_GLOBAL</b> synchronization, there may only be one thread executing in queues A1, A2, A3, A4, B1, B2, B3, or B4 at any one time. </p></dd></dl></dd></dl><dl class="margin"><dd><table border="0" cellpadding="3" cellspacing="0"><tr valign="top"><td valign="top" width="40"><a name="89365" class="autotag"><br></a><img border="0" alt="*" src="../../icons/note.gif"> </td><td><div class="Note"><hr><b class="symbol_UC">NOTE: </b> All of the synchronization levels prohibit multiple threads in the same queue at the same time.<hr></div></td></tr></table></dd></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H3"><i><a name="89361" class="autotag">4.1.2 Synchronization During Open and Close Procedures</a></i></h4></font><dl class="margin"><dd><dl class="margin"><dd><p class="Body"><a name="89362" class="autotag"> </a>A STREAMS component that shares data only during an open or close procedure would normally require the synchronization level <b>SQLVL_MODULE</b>. However, WindNet STREAMS allows you to take advantage of the greater flexibility in <b>SQLVL_QUEUE</b> or <b>SQLVL_QUEUEPAIR</b> when installing into WindNet STREAMS components that execute open and close procedures.</p><p class="Body"><a name="71836" class="autotag"> </a>In WindNet STREAMS, regardless of the assigned synchronization level, all open and close procedures execute in a temporary level of synchronization equivalent to <b>SQLVL_MODULE</b>. During an open or a close, this special synchronization status supersedes settings of <b>SQLVL_QUEUE</b> or <b>SQLVL_QUEUEPAIR</b>. Synchronization of open and close procedures by WindNet STREAMS permits exclusive access to global data structures shared by component instances without forcing normal put processing to occur at the <b>SQLVL_MODULE</b> level. </p><p class="Body"><a name="78634" class="autotag"> </a>For example, when opened, you may want a STREAMS component to link its instance data into a global list of component instances. In an open routine, the instance is guaranteed that it is the only active one of this component; therefore it's data can safely be linked to a global list without calling any special locking routines. </p><p class="Body"><a name="78635" class="autotag"> </a> If a STREAMS component must invoke <b class="routine"><i class="routine">strmSleep</i></b><b>( )</b> during an open or a close, WindNet STREAMS permits other instances of this component to execute at the configured synchronization level. When the STREAMS component wakes up, WindNet STREAMS ensures that the special synchronization of an open or close procedure is in effect before control is returned to those routines. The <b class="routine"><i class="routine">strmSleep</i></b><b>( )</b> and <b class="routine"><i class="routine">strmWakeup</i></b><b>( )</b> routines emulate UNIX sleep and wakeup functions. For more information, see the related manual entries.</p><p class="Body"><a name="86819" class="autotag"> </a>For more information about the synchronization of instances of different STREAMS components, see <a href="streams.doc13.html#82727"><i class="title">§4.1.3.1 Writer Buddies</i></a>.</p></dd></dl></dd></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H3"><i><a name="71839" class="autotag">4.1.3 Service and Put Procedures Synchronization</a></i></h4></font><dl class="margin"><dd><dl class="margin"><dd><p class="Body"><a name="71840" class="autotag"> </a>Synchronization for put and service procedures is not the same as that provided for open and close procedures. When writing shared data using put and service procedures, synchronization must be coordinated between STREAMS instances. It is better to avoid sharing data across component instances to avoid incurring synchronization overhead. In cases when synchronization is necessary, WindNet STREAMS provides two ways to proceed.</p><p class="Body"><a name="86837" class="autotag"> </a>The first method uses <b class="routine"><i class="routine">strmSyncWriteAccess</i></b><b>( )</b> to control instances through the execution of the entire put or service procedure. Instances in single or multiple components that can be synchronized using this routine must be writer buddies (see <a href="streams.doc13.html#82727"><i class="title">§4.1.3.1 Writer Buddies</i></a>). </p><p class="Body"><a name="89376" class="autotag"> </a>The second method uses VxWorks semaphores to synchronize instances only at necessary sections of code in the execution of the put or services procedures, thus providing a finer resolution to synchronization.</p></dd></dl></dd></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H4"><i><a name="82727" class="autotag">Writer Buddies</a></i></h4></font><dl class="margin"><dd><dl class="margin"><dd><p class="Body"><a name="86841" class="autotag"> </a>A writer buddy is an instance of a WindNet STREAMS component that can gain exclusive access to a resource in a multi-threaded environment like WindNet STREAMS because of its association with other instances. Instances of a single component are designated writer buddies by default upon installation in WindNet STREAMS. Instances of different components can also be made writer buddies manually during installation by calling <b class="routine"><i class="routine">strmDriverAdd</i></b><b>( )</b> or <b class="routine"><i class="routine">strmModuleAdd</i></b><b>( )</b>, see <a href="streams.doc16.html#72104"><i class="title">§4.4 Configuration of STREAMS Drivers and Modules in WindNet STREAMS</i></a>. </p><p class="Body"><a name="86845" class="autotag"> </a>It is this association of instances as writer buddies that ensures the execution of an open or close by only one member instance at a time; see <a href="streams.doc13.html#89361"><i class="title">§4.1.2 Synchronization During Open and Close Procedures</i></a>).</p><p class="Body"><a name="87121" class="autotag"> </a>Writer buddies can exist across multiple STREAMS components. Referring to <a href="streams.doc13.html#87215"><i class="title">Figure 13</i></a>, Components A and B can be associated as writer buddies. This association implies that when an instance of Component A is opened or closed, all other instances of A and B will be locked out while the new instance of A executes its open routine. So, the special synchronization of open and close procedures presented in <a href="streams.doc13.html#89361"><i class="title">§4.1.2 Synchronization During Open and Close Procedures</i></a> applies to both components. The cross-component association of writer-buddy instances of Components A and B can be established when the components are installed in WindNet STREAMS; see <a href="streams.doc16.html#72104"><i class="title">§4.4 Configuration of STREAMS Drivers and Modules in WindNet STREAMS</i></a>. <div class="frame"><h4 class="EntityTitle"><a name="87215" class="autotag"><font face="Helvetica, sans-serif" size="-1" class="sans">Figure 14. Writer Buddies</font></a></h4><div class="CellBody"><a name="87212" class="autotag"> </a><img class="figure" border="0" alt="" src="images/streams.doc.anc12.gif"></div></div> </p><p class="Body"><a name="86859" class="autotag"> </a>Component instances that are members of a writer buddy set can also be synchronized to have exclusive access to shared resources during put and service procedures by invoking the routine <b class="routine"><i class="routine">strmSyncWriteAccess</i></b><b>( )</b>; see <a href="streams.doc13.html#71841"><i class="title">§4.1.3.2 Updating Shared Data with strmSyncWriteAccess( )</i></a>.</p></dd></dl></dd></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H4"><i><a name="71841" class="autotag">Updating Shared Data with <b class="routine"><i class="routine">strmSyncWriteAccess</i></b><b>( )</b></a></i></h4></font><dl class="margin"><dd><dl class="margin"><dd><p class="Body"><a name="86864" class="autotag"> </a>The <b class="routine"><i class="routine">strmSyncWriteAccess</i></b><b>( )</b> routine coordinates multiple instances of a single component, as well as those in different components, so they can access shared resources one at a time. It is important that all instances synchronized by <b class="routine"><i class="routine">strmSyncWriteAccess</i></b><b>( )</b>already be designated writer buddies before calls are made to the routine. </p><p class="Body"><a name="86918" class="autotag"> </a>The routine <b class="routine"><i class="routine">strmSyncWriteAccess</i></b><b>( )</b> allows a single instance of a writer buddy set to gain exclusive access to a shared data structure from a put or service procedure. This mechanism works asynchronously, that is, <b class="routine"><i class="routine">strmSyncWriteAccess</i></b><b>( )</b> does not necessarily execute upon its invocation. The caller of <b class="routine"><i class="routine">strmSyncWriteAccess</i></b><b>( )</b> must provide: </p>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -