[go: up one dir, main page]

WO2012159309A1 - Method and device for processing data by utilizing threads - Google Patents

Method and device for processing data by utilizing threads Download PDF

Info

Publication number
WO2012159309A1
WO2012159309A1 PCT/CN2011/076552 CN2011076552W WO2012159309A1 WO 2012159309 A1 WO2012159309 A1 WO 2012159309A1 CN 2011076552 W CN2011076552 W CN 2011076552W WO 2012159309 A1 WO2012159309 A1 WO 2012159309A1
Authority
WO
WIPO (PCT)
Prior art keywords
thread
data
processing
critical resource
occupied
Prior art date
Application number
PCT/CN2011/076552
Other languages
French (fr)
Chinese (zh)
Inventor
周毅
Original Assignee
华为技术有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 华为技术有限公司 filed Critical 华为技术有限公司
Priority to PCT/CN2011/076552 priority Critical patent/WO2012159309A1/en
Priority to CN201180000911.9A priority patent/CN103608775B/en
Publication of WO2012159309A1 publication Critical patent/WO2012159309A1/en

Links

Classifications

    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/52Program synchronisation; Mutual exclusion, e.g. by means of semaphores

Definitions

  • the present invention relates to the field of communications technologies, and in particular, to a method and apparatus for processing data using threads. Background technique
  • ATM Asynchronous Transfer Mode
  • a physical link is usually divided into multiple virtual paths (VPs, Virtual Paths).
  • Each VP is identified by a virtual channel identifier (VPI), and each VP can carry multiple virtual paths (VC, Virtual).
  • VC virtual path identifier
  • the VCs on different VPs constitute a VC connection (VCC) for transmitting ATM cells, which is uniquely identified by the VCI of the VC and the VPI of the VP carrying the VC.
  • VCC VC connection
  • the header portion of the transport ATM cell includes an identifier for identifying the VC connection to which it is transmitted, gp VCI and VPI.
  • the ATM network is divided into three layers: ATM Adaptation Layer (AAL), ATM layer, and physical layer.
  • AAL layer is located at the upper layer of the ATM and is responsible for splitting the data transmitted from the upper layer into ATM cells and transmitting them to the ATM layer, and reassembling the ATM cells from the ATM layer into data and transmitting them to the upper layer.
  • the AAL layer is further divided into two sub-layers, namely a convergence (CS, Convergence Sublayer) sub-layer and a disassembly (SAR, Segmentation And Reassembly) sub-layer, wherein the CS sub-layer mainly implements a convergence function for transforming data into CS data units.
  • the SAR sublayer is mainly used to segment or recombine CS data in units of ATM cells.
  • the AAL layer has different AAL protocols, each of which is used to support different traffic or service types used on an ATM network.
  • ATM Adaptation Layer 2 (AAL2) is one of the AAL protocols that supports connection-oriented, variable bit rate services.
  • the AAL2 protocol is widely used, and the common services are compressed packet voice communication and compressed video transmission.
  • the AAL2 protocol processing is more complicated. Specifically, in the AAL2 protocol, when coming from the upper level (should When a service specific segmentation and reassembly (SSSAR) message (for example, a voice message) is to be transmitted via a VC connection, AAL2 fragmentation processing needs to be performed on the SSSAR message, gp: first The SSSAR message is split into a Common Part Sublayer (CPS) message, and then the split CPS message is filled into the ATM cell and sent to the ATM layer, where a CPS message is sent. A text can be filled across multiple ATM cells, and a single ATM cell can contain multiple CPS messages.
  • SSSAR service specific segmentation and reassembly
  • CPS Common Part Sublayer
  • AAL2 reassembly processing needs to be performed on the ATM cell, gP: first extracting the CPS message from the ATM cell, and then extracting the extracted CPS message. Reconstitute the SSSAR message and send it to the upper layer. Due to the complexity of the AAL2 protocol, its data processing performance is low. Summary of the invention
  • embodiments of the present invention provide a method and apparatus for processing data using threads that use multiple threads to process data in parallel, thereby improving the processing performance of the data.
  • An embodiment of the present invention provides a method for processing data in a first thread, including the steps of: detecting, when the first thread receives data that needs to perform specified processing, detecting that the specified processing is performed on the data Whether the resource has been occupied by another thread; and, when the detection result is positive, the data is sent to the processing wait queue of the other thread.
  • An embodiment of the present invention provides an apparatus for processing data in a first thread, including: a detecting module, configured to: when the first thread receives data that needs to perform specified processing, detecting that performing the data on the data Specifying whether a critical resource required for processing has been occupied by another thread; and, a sending module, configured to send the data to a processing wait queue of the another thread when the detection result is positive.
  • the method and apparatus of the embodiments of the present invention use multiple threads to process data in parallel, and data that needs to be processed using the same critical resource will be processed by only one thread, and different threads process data requiring different critical resources, so Synchronization and order preservation are not required between threads, which improves data processing performance.
  • FIG. 1 is a flow chart showing a method of processing data using a thread according to a first embodiment of the present invention
  • FIG. 2 shows a specific example of performing AAL2 fragmentation processing on data by using the method of the first embodiment of the present invention
  • FIG. 3 shows a specific example of performing AAL2 recombination processing on data by using the method of Embodiment 1 of the present invention
  • Embodiments of the present invention provide a method and apparatus for processing data using threads that employ multiple threads to process data in parallel, and data that needs to be processed using the same critical resource will be processed by only one of the threads. Different threads process data that requires different critical resources, so synchronization and ordering are not required between threads, which speeds up data processing.
  • a critical resource refers to a resource that is only allowed to be occupied by one thread at a time, including but not limited to a printer, a tape drive, a message buffer queue, a variable, an array, and/or a buffer.
  • FIG. 1 is a flow chart showing a method of processing data using a thread according to a first embodiment of the present invention.
  • multiple threads are used to process multiple data streams that need to perform specified processing in parallel, and each data of each data stream needs to be processed using the same critical resource, but each data stream needs to use different critical resources. Processing, each thread has a processing wait queue for saving pending data.
  • step S110 when any one of the plurality of threads receives the data D that needs to perform the specified processing, the thread P detects whether the critical resource R required to perform the specified processing on the data D has been Occupied by another thread.
  • step S120 when the detection result of step S110 is affirmative, that is, the critical resource R has been occupied by another thread, the thread P sends the data D to the processing wait queue of the other thread, to the data by the other thread. D is processed. Then, thread P continues to receive the next data 0 that needs to perform the specified processing.
  • step S130 when the detection result of step S110 is negative, that is, the critical resource R has not been occupied by another thread, the thread P occupies the critical resource R.
  • step S140 the thread P performs specified processing on the data D using the occupied critical resource R.
  • step S150 after the specified processing is performed on the data D by using the critical resource R, the thread P checks whether the data sent by the other thread is stored in the processing waiting queue. In this embodiment, after the thread P occupies the critical resource R, when other threads receive the data that needs to be processed by using the critical resource R, the data is sent to the processing wait queue of the thread P, to be performed by the thread P. deal with.
  • step S160 when the result of the check in step S150 is affirmative, that is, the data sent by the other thread is stored in the processing waiting queue of the thread P, the thread P performs the designation of the data held in the processing queue of the thread P by using the critical resource R. deal with.
  • step S170 when the check result of step S150 is negative, that is, the data sent by the other thread is not stored in the processing wait queue of the thread P, or the data held in the processing wait queue of the thread P has been processed, the thread P is released. Occupation of critical resource R. Then, thread P continues to receive other data that needs to perform the specified processing.
  • FIG. 2 shows a specific example of performing AAL2 fragmentation processing on data using the method of the first embodiment of the present invention.
  • multiple threads are used to perform AAL2 fragmentation processing in parallel on multiple data streams that need to be transmitted via different VCCs, where each data stream includes multiple SSSAR messages.
  • FIG. 2 shows a specific example of performing AAL2 fragmentation processing on data using the method of the first embodiment of the present invention.
  • multiple threads are used to perform AAL2 fragmentation processing in parallel on multiple data streams that need to be transmitted via different VCCs, where each data stream includes multiple SSSAR messages.
  • step S210 when any one of the plurality of threads receives a SSSAR message SB from the upper layer that needs to perform AAL2 fragmentation processing, the thread C attempts to VC the message SB to be transmitted.
  • the connection XT applies a mutex to detect whether the critical resource ZY required to perform AAL2 fragmentation processing on the message SB is already occupied by another thread.
  • the critical resource ZY may include, but is not limited to, a context in which AAL2 fragmentation processing is performed on SSSAR messages.
  • step S220 when the thread C fails to apply the mutex lock to the VC connection XT, it indicates that the critical resource ZY has been occupied by another thread, and the thread C sends the message SB to the processing waiting queue of the other thread. Another thread performs AAL2 fragmentation on the message SB. Then, thread C continues to receive the next SSSAR message that needs to perform AAL2 fragmentation processing from the upper layer.
  • step S230 when the thread C successfully applies the mutex lock to the VC connection XT, it is determined that the critical resource ZY has not been occupied by another thread, so that the thread C occupies the critical resource by applying a mutex lock to the VC connection XT. ZY.
  • step S240 the thread C performs AAL2 fragmentation processing on the message SB by using the occupied critical resource ZY to divide the message SB into ATM cells, wherein each ATM cell includes a VPI for identifying the VC connection XT. And VCI.
  • step S250 after performing AAL2 fragmentation processing on the message SB by using the critical resource ZY, the thread C checks whether the SSSAR message sent by another thread is stored in the processing waiting queue. In this example, after thread C occupies critical resource ZY, when other threads receive SSSAR messages that need to be processed using critical resource ZY, the SSSAR message is sent to thread C's processing wait queue.
  • step S260 when the check result of step S250 is affirmative, that is, when the processing wait queue of the thread C stores the SSSAR message sent by another thread, the thread C uses the occupied critical resource ZY to process the thread C in the waiting queue.
  • the saved SSSAR message performs AAL2 fragmentation processing to be segmented into ATM cells, where each ATM cell includes a VPI and a VCI for identifying the VC connection XT.
  • step S270 when the check result of step S250 is negative, that is, the SSSAR message sent by another thread is not stored in the processing waiting queue of the thread C, or the thread C processes the SSSAR message stored in the processing waiting queue, Thread C releases the occupancy of critical resource ZY. Then, thread C continues to receive other SSSAR messages from the upper layer that need to perform AAL2 fragmentation processing.
  • FIG. 3 shows a specific example of AAL2 recombination of data using the method of Embodiment 1 of the present invention. In this example, multiple threads are used to perform AAL2 reassembly processing in parallel on multiple data streams received from different VC connections, where each data stream includes multiple ATM cells.
  • step S310 when any one of the plurality of threads receives an ATM cell XY that needs to perform AAL2 reassembly processing from the ATM layer, the thread K is included according to the ATM cell XY.
  • the VPI and the VCI recognize the VC connection ST receiving the ATM cell XY, and attempt to apply a mutex lock to the VC connection ST to detect whether the critical resource U required for performing the AAL2 reassembly processing on the ATM cell XY has been used by another thread. Occupied.
  • the critical resource LJ may include, but is not limited to, a context in which AAL2 reassembly processing is performed on ATM cells.
  • step S320 when the thread K fails to apply the mutex lock to the VC connection ST, it indicates that the critical resource U has been occupied by another thread, and the thread K sends the ATM cell XY to the processing waiting queue of the other thread. The other thread performs AAL2 reassembly processing on the ATM cell XY. Then, thread K continues to receive the next ATM cell that needs to perform AAL2 reassembly processing from the ATM layer.
  • step S330 when the thread K successfully applies the mutex lock to the VC connection ST, it indicates that the critical resource U has not been occupied by another thread, so that the thread K occupies the critical resource by applying a mutex lock to the VC connection ST. U.
  • step S340 the thread K performs AAL2 reassembly processing on the ATM cell XY by using the occupied critical resource U to obtain an SSSAR message.
  • step S350 after the AAL2 reorganization processing is performed on the ATM cell XY by using the critical resource U, the thread K checks whether the ATM cell transmitted by another thread is stored in the processing waiting queue.
  • the thread K occupies the critical resource U, when other threads receive the ATM cell that needs to be processed by the critical resource U, the ATM cell is sent to the processing wait queue of the thread K, Thread K is processed.
  • step S360 when the check result of step S350 is affirmative, that is, when the processing wait queue of the thread K stores ATM cells transmitted by other threads, the thread K uses the occupied critical resource U to process the thread K in the waiting queue.
  • the saved ATM cell performs AAL2 reassembly processing to obtain an SSSAR message.
  • step S370 when the check result of step S350 is negative, that is, the ATM cell sent by another thread is not stored in the processing waiting queue of the thread K, or the thread K processes the ATM cell saved in the processing waiting queue, Thread K releases the occupation of critical resource U. Then, thread K continues to receive other ATM cells from the ATM layer that need to perform AAL2 reassembly processing.
  • the mutex is applied to the VC connection to detect whether the corresponding critical resource has been occupied by another thread, the present invention is not limited thereto. In other embodiments of the present invention, for example, a mutex may also be directly applied to the critical resource to detect whether the corresponding critical resource has been occupied by another thread.
  • the processing wait queue of each thread may include a plurality of processing wait queues having different priorities, when one thread sends the received data to the processing wait queue of another thread for execution by the other thread.
  • the priority of the received data is first identified, and then the received data is sent to a processing wait queue in the other thread corresponding to the priority of the received data.
  • a thread processes the data held by its processing wait queues, it processes the data held by each processing wait queue according to the priority of its processing wait queues from high to low.
  • FIG. 4 there is shown an apparatus for processing data in a first thread in accordance with an embodiment of the present invention, wherein the first thread is any of a plurality of threads.
  • the device 400 includes a detection module 410 and a sending module 420, where the detecting module 410 is configured to perform a specified processing on the data received by the first thread when the first thread receives the data that needs to perform the specified processing. Whether the required critical resource has been occupied by another thread, and the sending module 420 is configured to send the data received by the first thread to the processing waiting queue of the other thread when the detection result of the detecting module 410 is positive.
  • the device 400 may further include an occupation module 430 and an execution module 440, wherein the occupation module 430 is configured to occupy the critical resource for the first thread when the detection result of the detection module 410 is negative, and the execution module 440 is configured to utilize the The occupied critical resource for the first thread performs a specified process on the data received by the first thread.
  • the sending module 420 may further include an identifying module and a transmitting module, wherein the identifying module is configured to identify a priority of the data received by the first thread when the detection result of the detecting module 410 is positive, and the transmitting module is configured to The data received by one thread is sent to the processing wait queue of the other thread corresponding to the priority of the data received by the first thread.
  • the device 400 may further include an checking module 450 and a releasing module 460, wherein the checking module 450 is configured to check whether the data sent by the other thread is saved in the processing waiting queue of the first thread after performing the specified processing on the data received by the first thread.
  • the release module 460 is configured to release the occupied critical resource for the first thread when the check result of the check module 450 is negative, or when the execution module 440 processes the data held by the processing queue of the first thread.
  • the execution module 440 is further configured to: when the check result of the check module 450 is affirmative, use the occupied critical resource pair for the first thread according to the priority of the processing queue of the first thread from the highest to the lowest priority. The processing of the first thread waits for the data held by the queue to perform the specified processing.
  • the detecting module 410 may further include an applying module and a determining module, wherein the applying module is configured to apply a mutual exclusion lock of the first thread to a critical resource required to process the data received by the first thread, and the determining module is configured to apply When the mutex fails, it is determined that the critical resource is already occupied by another thread.
  • the data received by the first thread may be an SSSAR message that needs to be split into ATM cells
  • the specified processing may be AAL2 fragmentation processing
  • the critical resources required to process the data received by the first thread may be It is a critical resource related to the VC connection of ATM cells that send SSSAR messages.
  • the data received by the first thread may be an ATM cell that needs to be reassembled into an SSSAR message
  • the specified process may be AAL2 reassembly processing
  • the critical resource required to process the data received by the first thread may be the received SSSAR.
  • each module included in the device 400 can be implemented by using software, hardware or a combination of software and hardware.
  • Embodiments of the present invention also provide a machine readable storage medium storing machine executable instructions, wherein when the machine executable instructions are executed, causing a machine to implement a method for processing data in a first thread, the method comprising the Step: When the first thread receives the data that needs to perform the specified processing, it detects whether the critical resource required to perform the specified processing on the received data has been occupied by another thread; when the detection result is positive, the received The data is sent to the processing queue of the other thread.
  • the method may further include the following steps: when the detection result is negative, occupying the required critical resource for the first thread; performing the designation on the received data by using the occupied critical resource for the first thread deal with.
  • the method may further include the following steps: after performing the specified processing on the received data, checking whether the data sent by the other thread is saved in the processing waiting queue of the first thread; when the check result is positive, according to the first
  • the processing of the thread waits for the priority of the queue from high to low, and performs the specified processing on the data held by the processing queue of the first thread by using the critical resource occupied by the first thread; when the check result is negative, Release the critical resources used for the first thread.
  • the transmitting step described above may further include the following steps: when the detection result is positive, identifying the priority of the received data; transmitting the received data to the other thread and the received The priority of the data corresponds to the processing wait queue.
  • the detecting step described above may further include the steps of: applying a mutex of the first thread to the required critical resource; determining that the required critical resource has been used by the other when the mutex is failed to be applied A thread is occupied.
  • the received data may be an SSSAR message that needs to be split into ATM cells
  • the specified processing may be AAL2 fragmentation processing
  • the required critical resource may be an ATM cell that sends an SSSAR message.
  • the virtual path is connected to the related critical resource, or the received data may be an ATM cell that needs to be reassembled into an SSSAR message, and the specified process may be AAL2 reassembly processing, and the required critical resource may be the same as receiving the SSSAR message.
  • the virtual path of the ATM cell is connected to the critical resource.

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Data Exchanges In Wide-Area Networks (AREA)

Abstract

A method and a device for processing data by utilizing threads are provided. The method comprises: when the data, to which given processing needs to be performed, are received by a first thread, whether the critical resource required by performing the given processing to the data has been occupied by another thread or not is detected, and the data are sent to a processing waiting queue of another thread when the detection result is that the critical resource required by performing the given processing to the data has been occupied by another thread. The performance of data processing is improved by using the method and the device.

Description

技术领域 Technical field
本发明涉及通信技术领域, 特别涉及一种利用线程处理数据的方法及 装置。 背景技术  The present invention relates to the field of communications technologies, and in particular, to a method and apparatus for processing data using threads. Background technique
异步传输模式 (ATM, Asynchronous Transfer Mode)技术是在分组交换 原理的基础上发展起来的一种面向连接的通信技术, 其以 ATM信元为单位 在物理链路上传输数据。  Asynchronous Transfer Mode (ATM) technology is a connection-oriented communication technology developed on the basis of the principle of packet switching. It transmits data on a physical link in units of ATM cells.
在 ATM技术中, 一条物理链路通常划分成多条虚通道 (VP , Virtual Path), 每条 VP用虚通道标识符 (VPI) 标识, 每条 VP又可以承载多条虚通 路 (VC, Virtual Channel), 每条 VC用虚通路标识符 (VCI) 标识。 不同 VP 上的 VC构成用于传输 ATM信元的 VC连接 (VCC) , 其由 VC的 VCI和承载 该 VC的 VP的 VPI—起来唯一标识。传输 ATM信元的信头部分包括有用于识 别传输其的 VC连接的标识符, gp VCI和 VPI。  In the ATM technology, a physical link is usually divided into multiple virtual paths (VPs, Virtual Paths). Each VP is identified by a virtual channel identifier (VPI), and each VP can carry multiple virtual paths (VC, Virtual). Channel), each VC is identified by a virtual path identifier (VCI). The VCs on different VPs constitute a VC connection (VCC) for transmitting ATM cells, which is uniquely identified by the VCI of the VC and the VPI of the VP carrying the VC. The header portion of the transport ATM cell includes an identifier for identifying the VC connection to which it is transmitted, gp VCI and VPI.
ATM 网络分为三层: ATM 适配层 (AAL, ATM Adaptation Layer ) 、 ATM层和物理层。 AAL层位于 ATM的上层, 负责将高层传来的数据拆分 成 ATM信元并传送给 ATM层, 以及将来自 ATM层的 ATM信元重组成数 据并传送给高层。 AAL层进一步分成两个子层, 即会聚 (CS, Convergence Sublayer) 子层和拆装 (SAR, Segmentation And Reassembly) 子层, 其中, CS子层主要实现会聚功能, 用于将数据变换成 CS数据单元, 而 SAR子层主 要用于以 ATM信元为单位对 CS数据进行分段或重组。  The ATM network is divided into three layers: ATM Adaptation Layer (AAL), ATM layer, and physical layer. The AAL layer is located at the upper layer of the ATM and is responsible for splitting the data transmitted from the upper layer into ATM cells and transmitting them to the ATM layer, and reassembling the ATM cells from the ATM layer into data and transmitting them to the upper layer. The AAL layer is further divided into two sub-layers, namely a convergence (CS, Convergence Sublayer) sub-layer and a disassembly (SAR, Segmentation And Reassembly) sub-layer, wherein the CS sub-layer mainly implements a convergence function for transforming data into CS data units. The SAR sublayer is mainly used to segment or recombine CS data in units of ATM cells.
AAL层具有不同的 AAL协议,其中各个 AAL协议用于支持在 ATM 网 络上使用的不同的流量或服务类型。 ATM适配层 2 (AAL2)是 AAL协议的 其中一种, 其支持面向连接的比特率可变的业务。 AAL2协议应用广泛, 常 见的业务为压缩的分组语音通信和压缩的视频传输。  The AAL layer has different AAL protocols, each of which is used to support different traffic or service types used on an ATM network. ATM Adaptation Layer 2 (AAL2) is one of the AAL protocols that supports connection-oriented, variable bit rate services. The AAL2 protocol is widely used, and the common services are compressed packet voice communication and compressed video transmission.
AAL2协议处理比较复杂。 具体地, 在 AAL2协议中, 当来自高层 (应 用层) 的业务特定拆装子层 (SSSAR, Service Specific Segmentation and Reassembly) 报文 (例如语音报文) 要经由 VC连接进行发送时, 需要对该 SSSAR报文执行 AAL2分片处理, gp : 首先将该 SSSAR报文拆分为公用部件 子层 (CPS, Common Part Sublayer) 报文, 然后再所拆分的 CPS报文填写 到 ATM信元中并把其发送给 ATM层, 其中, 一个 CPS报文可以跨多个 ATM 信元填充, 而单个 ATM信元可以包含多个 CPS报文。 当来自 ATM层的经由 VC连接接收的 ATM信元要传递给高层时, 需要对 ATM信元执行 AAL2重组 处理, gP : 首先从 ATM信元中提取 CPS报文, 然后把所提取的 CPS报文重组 成 SSSAR报文并发送给高层。 由于 AAL2协议的复杂性, 导致其数据处理性 能较低。 发明内容 The AAL2 protocol processing is more complicated. Specifically, in the AAL2 protocol, when coming from the upper level (should When a service specific segmentation and reassembly (SSSAR) message (for example, a voice message) is to be transmitted via a VC connection, AAL2 fragmentation processing needs to be performed on the SSSAR message, gp: first The SSSAR message is split into a Common Part Sublayer (CPS) message, and then the split CPS message is filled into the ATM cell and sent to the ATM layer, where a CPS message is sent. A text can be filled across multiple ATM cells, and a single ATM cell can contain multiple CPS messages. When an ATM cell received from the ATM layer via the VC connection is to be transmitted to the upper layer, AAL2 reassembly processing needs to be performed on the ATM cell, gP: first extracting the CPS message from the ATM cell, and then extracting the extracted CPS message. Reconstitute the SSSAR message and send it to the upper layer. Due to the complexity of the AAL2 protocol, its data processing performance is low. Summary of the invention
考虑到现有技术的上述缺陷, 本发明的实施例提出一种利用线程处理 数据的方法及装置, 其使用多个线程来并行处理数据, 从而提高数据的处 理性能。  In view of the above-discussed deficiencies of the prior art, embodiments of the present invention provide a method and apparatus for processing data using threads that use multiple threads to process data in parallel, thereby improving the processing performance of the data.
本发明实施例提供一种用于在第一线程中处理数据的方法, 包括步骤: 当所述第一线程接收到需要执行指定处理的数据时, 检测对所述数据执行 所述指定处理所需的资源是否已经被另一线程占用; 以及, 当所述检测结 果为肯定时, 将所述数据发送给所述另一线程的处理等待队列。  An embodiment of the present invention provides a method for processing data in a first thread, including the steps of: detecting, when the first thread receives data that needs to perform specified processing, detecting that the specified processing is performed on the data Whether the resource has been occupied by another thread; and, when the detection result is positive, the data is sent to the processing wait queue of the other thread.
本发明实施例提供一种用于在第一线程中处理数据的装置, 包括: 检 测模块, 用于当所述第一线程接收到需要执行指定处理的数据时, 检测对 所述数据执行所述指定处理所需的临界资源是否已经被另一线程占用; 以 及, 发送模块, 用于当所述检测结果为肯定时, 将所述数据发送给所述另 一线程的处理等待队列。  An embodiment of the present invention provides an apparatus for processing data in a first thread, including: a detecting module, configured to: when the first thread receives data that needs to perform specified processing, detecting that performing the data on the data Specifying whether a critical resource required for processing has been occupied by another thread; and, a sending module, configured to send the data to a processing wait queue of the another thread when the detection result is positive.
本发明实施例的方法和装置, 采用多个线程来并行处理数据, 并且需 要使用相同的临界资源来处理的数据将仅由其中一个线程来处理, 不同的 线程处理需要不同临界资源的数据, 因此线程之间不需要同步和保序, 从 而提高了数据的处理性能。 附图说明  The method and apparatus of the embodiments of the present invention use multiple threads to process data in parallel, and data that needs to be processed using the same critical resource will be processed by only one thread, and different threads process data requiring different critical resources, so Synchronization and order preservation are not required between threads, which improves data processing performance. DRAWINGS
本发明的目的、 特点、 特征和优点通过以下结合附图的详细描述将变 得显而易见。 其中: The objects, features, features and advantages of the present invention will become apparent from the following detailed description It’s obvious. among them:
图 1示出了根据本发明实施例一的利用线程来处理数据的方法的流程 示意图;  1 is a flow chart showing a method of processing data using a thread according to a first embodiment of the present invention;
图 2示出了利用本发明实施例一的方法来对数据进行 AAL2分片处理的 一个具体示例;  FIG. 2 shows a specific example of performing AAL2 fragmentation processing on data by using the method of the first embodiment of the present invention;
图 3示出了利用本发明实施例一的方法来对数据进行 AAL2重组处理的 一个具体示例; 以及  FIG. 3 shows a specific example of performing AAL2 recombination processing on data by using the method of Embodiment 1 of the present invention;
图 4示出了按照本发明实施例的在第一线程中处理数据的装置。 具体实施方式 本发明的实施例提供一种利用线程来处理数据的方法和装置, 其采用 多个线程来并行处理数据, 并且需要使用相同的临界资源来处理的数据将 仅由其中一个线程来处理, 不同的线程处理需要不同临界资源的数据, 因 此线程之间不需要同步和保序, 从而加快了数据处理的速度。 这里, 如本 领域技术人员所理解的, 临界资源是指每次仅允许一个线程占用的资源, 包括但不局限于打印机、 磁带机、 消息缓冲队列、 变量、 数组和 /或缓冲区 等。  4 illustrates an apparatus for processing data in a first thread in accordance with an embodiment of the present invention. DETAILED DESCRIPTION OF THE INVENTION Embodiments of the present invention provide a method and apparatus for processing data using threads that employ multiple threads to process data in parallel, and data that needs to be processed using the same critical resource will be processed by only one of the threads. Different threads process data that requires different critical resources, so synchronization and ordering are not required between threads, which speeds up data processing. Here, as understood by those skilled in the art, a critical resource refers to a resource that is only allowed to be occupied by one thread at a time, including but not limited to a printer, a tape drive, a message buffer queue, a variable, an array, and/or a buffer.
下面将结合附图详细描述本发明的各个实施例。 图 1示出了根据本发明实施例一的利用线程来处理数据的方法的流程 示意图。 在本实施例中, 使用多个线程来并行处理多个需要执行指定处理 的数据流, 每个数据流的各个数据需要使用相同的临界资源来处理, 但各 个数据流需要使用不同的临界资源来处理, 每一个线程具有用于保存待处 理数据的处理等待队列。 Various embodiments of the present invention will be described in detail below with reference to the drawings. 1 is a flow chart showing a method of processing data using a thread according to a first embodiment of the present invention. In this embodiment, multiple threads are used to process multiple data streams that need to perform specified processing in parallel, and each data of each data stream needs to be processed using the same critical resource, but each data stream needs to use different critical resources. Processing, each thread has a processing wait queue for saving pending data.
如图 1所示, 在步骤 S110, 当该多个线程中的任意一个线程 P接收到需 要执行指定处理的数据 D时, 线程 P检测对数据 D执行指定处理所需的临界 资源 R是否已经被另一线程所占用。 在步骤 S120, 当步骤 S110的检测结果为肯定, 即临界资源 R已经被另一 线程所占用时, 线程 P将数据 D发送给该另一线程的处理等待队列, 以由该 另一线程对数据 D进行处理。 然后, 线程 P继续接收下一个需要执行指定处 理的数据0。 As shown in FIG. 1, in step S110, when any one of the plurality of threads receives the data D that needs to perform the specified processing, the thread P detects whether the critical resource R required to perform the specified processing on the data D has been Occupied by another thread. In step S120, when the detection result of step S110 is affirmative, that is, the critical resource R has been occupied by another thread, the thread P sends the data D to the processing wait queue of the other thread, to the data by the other thread. D is processed. Then, thread P continues to receive the next data 0 that needs to perform the specified processing.
在步骤 S130, 当步骤 S110的检测结果为否定, 即临界资源 R还没有被另 一线程所占用时, 线程 P占用临界资源 R。  In step S130, when the detection result of step S110 is negative, that is, the critical resource R has not been occupied by another thread, the thread P occupies the critical resource R.
在步骤 S140, 线程 P利用所占用的临界资源 R对数据 D执行指定处理。 在步骤 S150, 在利用临界资源 R对数据 D执行指定处理之后, 线程 P检 查其处理等待队列中是否保存有其它线程发送的数据。 在本实施例中, 在 线程 P占用了临界资源 R之后,当其它线程接收到需要使用临界资源 R来处理 的数据时, 都会把该数据发送到线程 P的处理等待队列, 以由线程 P进行处 理。  In step S140, the thread P performs specified processing on the data D using the occupied critical resource R. In step S150, after the specified processing is performed on the data D by using the critical resource R, the thread P checks whether the data sent by the other thread is stored in the processing waiting queue. In this embodiment, after the thread P occupies the critical resource R, when other threads receive the data that needs to be processed by using the critical resource R, the data is sent to the processing wait queue of the thread P, to be performed by the thread P. deal with.
在步骤 S160, 当步骤 S150的检查结果为肯定, 即线程 P的处理等待队列 中保存有其它线程发送的数据时,线程 P利用临界资源 R对线程 P的处理等待 队列中所保存的数据执行指定处理。  In step S160, when the result of the check in step S150 is affirmative, that is, the data sent by the other thread is stored in the processing waiting queue of the thread P, the thread P performs the designation of the data held in the processing queue of the thread P by using the critical resource R. deal with.
在步骤 S170, 当步骤 S150的检查结果为否定, 即线程 P的处理等待队列 中没有保存有其它线程发送的数据, 或者已经处理完线程 P的处理等待队列 中所保存的数据时, 线程 P释放对临界资源 R的占用。然后, 线程 P继续接收 需要执行指定处理的其它数据。  In step S170, when the check result of step S150 is negative, that is, the data sent by the other thread is not stored in the processing wait queue of the thread P, or the data held in the processing wait queue of the thread P has been processed, the thread P is released. Occupation of critical resource R. Then, thread P continues to receive other data that needs to perform the specified processing.
从上面的描述可知, 按照本实施例一的方案, 使用多个线程来并行处 理数据, 并且需要使用相同的临界资源来处理的数据将仅由其中一个线程 来处理, 不同的线程处理需要不同临界资源的数据, 因此线程之间不需要 同步和保序, 从而加快了数据处理的速度。 下面给出利用本实施例一所公开的方法来处理数据的具体示例。 图 2示出了利用本发明实施例一的方法来对数据进行 AAL2分片处理的 一个具体示例。 在本示例中, 利用多个线程来对多个需要经由不同的 VCC 进行发送的数据流并行地进行 AAL2分片处理, 其中, 每一个数据流包括多 个 SSSAR报文。 如图 2所示, 在步骤 S210, 当该多个线程中的任意一个线程 C从高层接 收到一个需要执行 AAL2分片处理的 SSSAR报文 SB时, 线程 C试图对将要发 送报文 SB的 VC连接 XT施加互斥锁,以检测对报文 SB执行 AAL2分片处理所 需的临界资源 ZY是否已经被另一线程所占用。在这里, 临界资源 ZY可以包 括但不局限于对 SSSAR报文执行 AAL2分片处理的上下文。 As can be seen from the above description, according to the solution of the first embodiment, multiple threads are used to process data in parallel, and data that needs to be processed using the same critical resource will be processed by only one thread, and different thread processing requires different criticalities. The data of the resource, so there is no need for synchronization and order preservation between threads, thus speeding up the processing of data. A specific example of processing data using the method disclosed in the first embodiment will be given below. FIG. 2 shows a specific example of performing AAL2 fragmentation processing on data using the method of the first embodiment of the present invention. In this example, multiple threads are used to perform AAL2 fragmentation processing in parallel on multiple data streams that need to be transmitted via different VCCs, where each data stream includes multiple SSSAR messages. As shown in FIG. 2, in step S210, when any one of the plurality of threads receives a SSSAR message SB from the upper layer that needs to perform AAL2 fragmentation processing, the thread C attempts to VC the message SB to be transmitted. The connection XT applies a mutex to detect whether the critical resource ZY required to perform AAL2 fragmentation processing on the message SB is already occupied by another thread. Here, the critical resource ZY may include, but is not limited to, a context in which AAL2 fragmentation processing is performed on SSSAR messages.
在步骤 S220, 当线程 C对 VC连接 XT施加互斥锁失败时, 表明临界资源 ZY已经被另一线程所占用, 线程 C将报文 SB发送给该另一线程的处理等待 队列, 以由该另一线程对报文 SB进行 AAL2分片处理。 然后, 线程 C继续从 高层接收下一个需要执行 AAL2分片处理的 SSSAR报文。  In step S220, when the thread C fails to apply the mutex lock to the VC connection XT, it indicates that the critical resource ZY has been occupied by another thread, and the thread C sends the message SB to the processing waiting queue of the other thread. Another thread performs AAL2 fragmentation on the message SB. Then, thread C continues to receive the next SSSAR message that needs to perform AAL2 fragmentation processing from the upper layer.
在步骤 S230, 当线程 C对 VC连接 XT施加互斥锁成功时, 确定临界资源 ZY还没有被另一线程所占用,从而线程 C就通过对 VC连接 XT施加了互斥锁 而占用了临界资源 ZY。  In step S230, when the thread C successfully applies the mutex lock to the VC connection XT, it is determined that the critical resource ZY has not been occupied by another thread, so that the thread C occupies the critical resource by applying a mutex lock to the VC connection XT. ZY.
在步骤 S240,线程 C利用所占用的临界资源 ZY对报文 SB执行 AAL2分片 处理, 以把报文 SB分割成 ATM信元, 其中, 每个 ATM信元包括有用于标识 VC连接 XT的 VPI和 VCI。  In step S240, the thread C performs AAL2 fragmentation processing on the message SB by using the occupied critical resource ZY to divide the message SB into ATM cells, wherein each ATM cell includes a VPI for identifying the VC connection XT. And VCI.
在步骤 S250, 在利用临界资源 ZY对报文 SB执行 AAL2分片处理之后, 线程 C检查其处理等待队列中是否保存有其它线程发送的 SSSAR报文。在本 示例中, 在线程 C占用了临界资源 ZY之后, 当其它线程接收到需要使用临 界资源 ZY来处理的 SSSAR报文时, 都会把该 SSSAR报文发送到线程 C的处 理等待队列。  In step S250, after performing AAL2 fragmentation processing on the message SB by using the critical resource ZY, the thread C checks whether the SSSAR message sent by another thread is stored in the processing waiting queue. In this example, after thread C occupies critical resource ZY, when other threads receive SSSAR messages that need to be processed using critical resource ZY, the SSSAR message is sent to thread C's processing wait queue.
在步骤 S260, 当步骤 S250的检查结果为肯定, 即线程 C的处理等待队列 中保存有其它线程发送的 SSSAR报文时, 线程 C利用所占用的临界资源 ZY 对线程 C的处理等待队列中所保存的 SSSAR报文执行 AAL2分片处理, 以分 割成 ATM信元,其中,每个 ATM信元包括用于标识 VC连接 XT的 VPI和 VCI。  In step S260, when the check result of step S250 is affirmative, that is, when the processing wait queue of the thread C stores the SSSAR message sent by another thread, the thread C uses the occupied critical resource ZY to process the thread C in the waiting queue. The saved SSSAR message performs AAL2 fragmentation processing to be segmented into ATM cells, where each ATM cell includes a VPI and a VCI for identifying the VC connection XT.
在步骤 S270, 当步骤 S250的检查结果为否定, 即线程 C的处理等待队列 中没有保存有其它线程发送的 SSSAR报文,或者线程 C处理完其处理等待队 列中所保存的 SSSAR报文时, 线程 C释放对临界资源 ZY的占用。 然后, 线 程 C继续从高层接收其它需要执行 AAL2分片处理的 SSSAR报文。 图 3示出了利用本发明实施例一的方法来对数据进行 AAL2重组的一个 具体示例。 在本示例中, 利用多个线程来对多个从不同的 VC连接接收的数 据流并行地进行 AAL2重组处理, 其中, 每一个数据流包括多个 ATM信元。 In step S270, when the check result of step S250 is negative, that is, the SSSAR message sent by another thread is not stored in the processing waiting queue of the thread C, or the thread C processes the SSSAR message stored in the processing waiting queue, Thread C releases the occupancy of critical resource ZY. Then, thread C continues to receive other SSSAR messages from the upper layer that need to perform AAL2 fragmentation processing. FIG. 3 shows a specific example of AAL2 recombination of data using the method of Embodiment 1 of the present invention. In this example, multiple threads are used to perform AAL2 reassembly processing in parallel on multiple data streams received from different VC connections, where each data stream includes multiple ATM cells.
如图 3所示, 在步骤 S310, 当该多个线程中的任意一个线程 K从 ATM层 接收到一个需要执行 AAL2重组处理的 ATM信元 XY时, 线程 K根据 ATM信 元 XY中所包括的 VPI和 VCI识别出接收 ATM信元 XY的 VC连接 ST, 并试图 对 VC连接 ST施加互斥锁,以检测对 ATM信元 XY执行 AAL2重组处理所需的 临界资源 U是否已经被另一线程所占用。 在这里, 临界资源 LJ可以包括但 不局限于对 ATM信元执行 AAL2重组处理的上下文。  As shown in FIG. 3, in step S310, when any one of the plurality of threads receives an ATM cell XY that needs to perform AAL2 reassembly processing from the ATM layer, the thread K is included according to the ATM cell XY. The VPI and the VCI recognize the VC connection ST receiving the ATM cell XY, and attempt to apply a mutex lock to the VC connection ST to detect whether the critical resource U required for performing the AAL2 reassembly processing on the ATM cell XY has been used by another thread. Occupied. Here, the critical resource LJ may include, but is not limited to, a context in which AAL2 reassembly processing is performed on ATM cells.
在步骤 S320, 当线程 K对 VC连接 ST施加互斥锁失败时, 表明临界资源 U已经被另一线程所占用, 线程 K将 ATM信元 XY发送给该另一线程的处理 等待队列, 以由该另一线程对 ATM信元 XY进行 AAL2重组处理。 然后, 线 程 K继续从 ATM层接收下一个需要执行 AAL2重组处理的 ATM信元。  In step S320, when the thread K fails to apply the mutex lock to the VC connection ST, it indicates that the critical resource U has been occupied by another thread, and the thread K sends the ATM cell XY to the processing waiting queue of the other thread. The other thread performs AAL2 reassembly processing on the ATM cell XY. Then, thread K continues to receive the next ATM cell that needs to perform AAL2 reassembly processing from the ATM layer.
在步骤 S330, 当线程 K对 VC连接 ST施加互斥锁成功时, 表明临界资源 U还没有被另一线程所占用, 从而线程 K就通过对 VC连接 ST施加了互斥锁 而占用了临界资源 U。  In step S330, when the thread K successfully applies the mutex lock to the VC connection ST, it indicates that the critical resource U has not been occupied by another thread, so that the thread K occupies the critical resource by applying a mutex lock to the VC connection ST. U.
在步骤 S340 , 线程 K利用所占用的临界资源 U对 ATM信元 XY执行 AAL2重组处理, 以得到 SSSAR报文。  In step S340, the thread K performs AAL2 reassembly processing on the ATM cell XY by using the occupied critical resource U to obtain an SSSAR message.
在步骤 S350, 在利用临界资源 U对 ATM信元 XY执行 AAL2重组处理之 后, 线程 K检查其处理等待队列中是否保存有其它线程发送的 ATM信元。 在本示例中, 在线程 K占用了临界资源 U之后, 当其它线程接收到需要使用 临界资源 U来处理的 ATM信元时, 都会把该 ATM信元发送到线程 K的处理 等待队列, 以由线程 K进行处理。  In step S350, after the AAL2 reorganization processing is performed on the ATM cell XY by using the critical resource U, the thread K checks whether the ATM cell transmitted by another thread is stored in the processing waiting queue. In this example, after the thread K occupies the critical resource U, when other threads receive the ATM cell that needs to be processed by the critical resource U, the ATM cell is sent to the processing wait queue of the thread K, Thread K is processed.
在步骤 S360, 当步骤 S350的检查结果为肯定, 即线程 K的处理等待队列 中保存有其它线程发送的 ATM信元时, 线程 K利用所占用的临界资源 U对 线程 K的处理等待队列中所保存的 ATM信元执行 AAL2重组处理, 以得到 SSSAR报文。  In step S360, when the check result of step S350 is affirmative, that is, when the processing wait queue of the thread K stores ATM cells transmitted by other threads, the thread K uses the occupied critical resource U to process the thread K in the waiting queue. The saved ATM cell performs AAL2 reassembly processing to obtain an SSSAR message.
在步骤 S370, 当步骤 S350的检查结果为否定, 即线程 K的处理等待队列 中没有保存有其它线程发送的 ATM信元, 或者线程 K处理完其处理等待队 列中所保存的 ATM信元时, 线程 K释放对临界资源 U的占用。 然后, 线程 K 继续从 ATM层接收其它需要执行 AAL2重组处理的 ATM信元。 本领域技术人员应当理解, 虽然在上面具体示例的描述中, 通过对 VC 连接施加互斥锁来检测相应的临界资源是否已经被另一线程占用, 然而, 本发明并不局限于此。 在本发明的其它实施例中, 例如, 也可以直接对临 界资源施加互斥锁来检测相应的临界资源是否已经被另一线程占用。 In step S370, when the check result of step S350 is negative, that is, the ATM cell sent by another thread is not stored in the processing waiting queue of the thread K, or the thread K processes the ATM cell saved in the processing waiting queue, Thread K releases the occupation of critical resource U. Then, thread K continues to receive other ATM cells from the ATM layer that need to perform AAL2 reassembly processing. It will be understood by those skilled in the art that although in the above specific example description, the mutex is applied to the VC connection to detect whether the corresponding critical resource has been occupied by another thread, the present invention is not limited thereto. In other embodiments of the present invention, for example, a mutex may also be directly applied to the critical resource to detect whether the corresponding critical resource has been occupied by another thread.
本领域技术人员应当理解, 各个线程的处理等待队列可以包括多个具 有不同优先级的处理等待队列, 当一个线程将所接收的数据发送到另一线 程的处理等待队列以由该另一线程进行处理时, 首先识别该接收的数据的 优先级, 然后将该接收的数据发送到该另一线程中的与该接收的数据的优 先级相应的处理等待队列中。 当一个线程对其各个处理等待队列所保存的 数据进行处理时, 按照其各个处理等待队列的优先级从高到低的顺序, 对 其各个处理等待队列所保存的数据进行处理。  It should be understood by those skilled in the art that the processing wait queue of each thread may include a plurality of processing wait queues having different priorities, when one thread sends the received data to the processing wait queue of another thread for execution by the other thread. In processing, the priority of the received data is first identified, and then the received data is sent to a processing wait queue in the other thread corresponding to the priority of the received data. When a thread processes the data held by its processing wait queues, it processes the data held by each processing wait queue according to the priority of its processing wait queues from high to low.
本领域技术人员应当理解, 本发明实施例所公开的方法不但可以用来 对数据执行 AAL2分片处理和 AAL2重组处理, 而且也对数据执行其它类型 的处理。 现在参考图 4, 其示出了按照本发明实施例的在第一线程中处理数据的 装置, 其中, 该第一线程是多个线程中的任意线程。  Those skilled in the art should understand that the method disclosed in the embodiments of the present invention can be used not only to perform AAL2 fragmentation processing and AAL2 reassembly processing on data, but also to perform other types of processing on data. Referring now to Figure 4, there is shown an apparatus for processing data in a first thread in accordance with an embodiment of the present invention, wherein the first thread is any of a plurality of threads.
如图 4所示, 装置 400包括检测模块 410和发送模块 420, 其中, 检测 模块 410用于当第一线程接收到需要执行指定处理的数据时, 检测对第一 线程所接收的数据执行指定处理所需的临界资源是否已经被另一线程占 用, 以及, 发送模块 420用于当检测模块 410的检测结果为肯定时, 将第 一线程所接收的数据发送给该另一线程的处理等待队列。  As shown in FIG. 4, the device 400 includes a detection module 410 and a sending module 420, where the detecting module 410 is configured to perform a specified processing on the data received by the first thread when the first thread receives the data that needs to perform the specified processing. Whether the required critical resource has been occupied by another thread, and the sending module 420 is configured to send the data received by the first thread to the processing waiting queue of the other thread when the detection result of the detecting module 410 is positive.
装置 400还可以包括占用模块 430和执行模块 440, 其中, 占用模块 430用于当检测模块 410的检测结果为否定时,占用该临界资源用于第一线 程, 以及, 执行模块 440用于利用该占用的用于第一线程的临界资源对第 一线程所接收的数据执行指定处理。  The device 400 may further include an occupation module 430 and an execution module 440, wherein the occupation module 430 is configured to occupy the critical resource for the first thread when the detection result of the detection module 410 is negative, and the execution module 440 is configured to utilize the The occupied critical resource for the first thread performs a specified process on the data received by the first thread.
发送模块 420还可以进一步包括识别模块和传递模块, 其中, 识别模 块用于当检测模块 410 的检测结果为肯定时, 识别第一线程所接收的数据 的优先级, 以及, 传递模块用于将第一线程所接收的数据发送给该另一线 程的与第一线程所接收的数据的优先级相对应的处理等待队列。 装置 400还可以包括检查模块 450和释放模块 460, 其中检查模块 450 用于在对第一线程所接收的数据执行指定处理后, 检查第一线程的处理等 待队列中是否保存有其它线程发送的数据, 释放模块 460用于当检查模块 450的检查结果为否定,或者当执行模块 440处理完第一线程的处理等待队 列所保存的数据时, 释放所占用的用于第一线程的临界资源。 其中, 执行 模块 440还用于当检查模块 450的检查结果为肯定时, 按照第一线程的处 理等待队列的优先级从高到低的顺序, 利用所占用的用于第一线程的临界 资源对第一线程的处理等待队列所保存的数据执行指定处理。 The sending module 420 may further include an identifying module and a transmitting module, wherein the identifying module is configured to identify a priority of the data received by the first thread when the detection result of the detecting module 410 is positive, and the transmitting module is configured to The data received by one thread is sent to the processing wait queue of the other thread corresponding to the priority of the data received by the first thread. The device 400 may further include an checking module 450 and a releasing module 460, wherein the checking module 450 is configured to check whether the data sent by the other thread is saved in the processing waiting queue of the first thread after performing the specified processing on the data received by the first thread. The release module 460 is configured to release the occupied critical resource for the first thread when the check result of the check module 450 is negative, or when the execution module 440 processes the data held by the processing queue of the first thread. The execution module 440 is further configured to: when the check result of the check module 450 is affirmative, use the occupied critical resource pair for the first thread according to the priority of the processing queue of the first thread from the highest to the lowest priority. The processing of the first thread waits for the data held by the queue to perform the specified processing.
检测模块 410还可以进一步包括施加模块和确定模块, 其中, 施加模 块用于对处理第一线程所接收的数据所需的临界资源施加第一线程的互斥 锁, 以及, 确定模块用于当施加互斥锁失败时, 确定该临界资源已经被另 一线程占用。  The detecting module 410 may further include an applying module and a determining module, wherein the applying module is configured to apply a mutual exclusion lock of the first thread to a critical resource required to process the data received by the first thread, and the determining module is configured to apply When the mutex fails, it is determined that the critical resource is already occupied by another thread.
其中, 例如, 第一线程所接收的数据可以是需要拆分为 ATM 信元的 SSSAR报文, 指定处理可以是 AAL2分片处理, 以及, 处理第一线程所接 收的数据所需的临界资源可以是与发送 SSSAR报文的 ATM信元的 VC连 接有关的临界资源。或者,第一线程所接收的数据可以是需要重组为 SSSAR 报文的 ATM信元, 指定处理可以是 AAL2重组处理, 以及, 处理第一线程 所接收的数据所需的临界资源可以是与接收 SSSAR报文的 ATM信元的 VC 连接有关的临界资源。  For example, the data received by the first thread may be an SSSAR message that needs to be split into ATM cells, and the specified processing may be AAL2 fragmentation processing, and the critical resources required to process the data received by the first thread may be It is a critical resource related to the VC connection of ATM cells that send SSSAR messages. Alternatively, the data received by the first thread may be an ATM cell that needs to be reassembled into an SSSAR message, the specified process may be AAL2 reassembly processing, and the critical resource required to process the data received by the first thread may be the received SSSAR. The critical resource of the VC connection of the ATM cell of the message.
本领域技术人员应当理解, 装置 400所包括的各个模块, 可以利用软 件、 硬件或者软硬件结合的方式来实现。  Those skilled in the art should understand that each module included in the device 400 can be implemented by using software, hardware or a combination of software and hardware.
本发明实施例还提供机器可读存储介质, 其存储有机器可执行指令, 其中, 当该机器可执行指令被执行时使得机器实施用于在第一线程中处理 数据的方法, 该方法包括以下步骤: 当第一线程接收到需要执行指定处理 的数据时, 检测对该接收到的数据执行指定处理所需的临界资源是否已经 被另一线程占用; 当检测结果为肯定时, 将该接收到的数据发送给该另一 线程的处理等待队列。  Embodiments of the present invention also provide a machine readable storage medium storing machine executable instructions, wherein when the machine executable instructions are executed, causing a machine to implement a method for processing data in a first thread, the method comprising the Step: When the first thread receives the data that needs to perform the specified processing, it detects whether the critical resource required to perform the specified processing on the received data has been occupied by another thread; when the detection result is positive, the received The data is sent to the processing queue of the other thread.
其中, 该方法还可以包括以下步骤: 当检测结果为否定时, 占用该所 需的临界资源用于第一线程; 利用所占用的用于第一线程的临界资源对该 接收到的数据执行指定处理。 其中, 该方法还可以包括以下步骤: 在对该接收到的数据执行指定处 理后, 检查第一线程的处理等待队列中是否保存有其它线程发送的数据; 当检查结果为肯定时, 按照第一线程的处理等待队列的优先级从高到低的 顺序, 利用所占用的用于第一线程的临界资源对第一线程的处理等待队列 所保存的数据执行指定处理; 当检查结果为否定时, 释放所占用的用于第 一线程的临界资源。 The method may further include the following steps: when the detection result is negative, occupying the required critical resource for the first thread; performing the designation on the received data by using the occupied critical resource for the first thread deal with. The method may further include the following steps: after performing the specified processing on the received data, checking whether the data sent by the other thread is saved in the processing waiting queue of the first thread; when the check result is positive, according to the first The processing of the thread waits for the priority of the queue from high to low, and performs the specified processing on the data held by the processing queue of the first thread by using the critical resource occupied by the first thread; when the check result is negative, Release the critical resources used for the first thread.
其中, 上面所描述的发送步骤还可以进一步包括以下步骤: 当检测结 果为肯定时, 识别该接收到的数据的优先级; 将该接收到的数据发送给该 另一线程的与该接收到的数据的优先级相对应的处理等待队列。  The transmitting step described above may further include the following steps: when the detection result is positive, identifying the priority of the received data; transmitting the received data to the other thread and the received The priority of the data corresponds to the processing wait queue.
其中, 上面所描述的检测步骤还可以进一步包括以下步骤: 对该所需 的临界资源施加第一线程的互斥锁; 当施加互斥锁失败时, 确定该所需的 临界资源已经被该另一线程占用。  The detecting step described above may further include the steps of: applying a mutex of the first thread to the required critical resource; determining that the required critical resource has been used by the other when the mutex is failed to be applied A thread is occupied.
其中, 例如, 该接收到的数据可以是需要拆分为 ATM信元的 SSSAR 报文, 指定处理可以是 AAL2分片处理, 该所需的临界资源可以是与发送 SSSAR报文的 ATM信元的虚通路连接有关的临界资源, 或者, 该接收到 的数据可以是需要重组为 SSSAR报文的 ATM信元,指定处理可以是 AAL2 重组处理, 该所需的临界资源可以是与接收 SSSAR报文的 ATM信元的虚 通路连接有关的临界资源。  For example, the received data may be an SSSAR message that needs to be split into ATM cells, and the specified processing may be AAL2 fragmentation processing, and the required critical resource may be an ATM cell that sends an SSSAR message. The virtual path is connected to the related critical resource, or the received data may be an ATM cell that needs to be reassembled into an SSSAR message, and the specified process may be AAL2 reassembly processing, and the required critical resource may be the same as receiving the SSSAR message. The virtual path of the ATM cell is connected to the critical resource.
本领域技术人员应当理解, 本发明的各个实施例所公开的方法和装置, 可以在不偏离发明实质的情况下做出各种变形和改变, 这些变形和改变都 应当落入在本发明的保护范围之内。 因此, 本发明的保护范围由所附的权 利要求书来定义。  It should be understood by those skilled in the art that the present invention may be variously modified and changed without departing from the spirit of the invention. Within the scope. Therefore, the scope of the invention is defined by the appended claims.

Claims

权 利 要 求 书 Claim
1、 一种用于在第一线程中处理数据的方法, 包括步骤: 1. A method for processing data in a first thread, comprising the steps of:
当所述第一线程接收到需要执行指定处理的数据时, 检测对所述数据 执行所述指定处理所需的临界资源是否已经被另一线程占用;  When the first thread receives the data that needs to perform the specified processing, it is detected whether the critical resource required to perform the specified processing on the data has been occupied by another thread;
当检测结果为肯定时, 将所述数据发送给所述另一线程的处理等待队 列。  When the result of the check is affirmative, the process of sending the data to the other thread waits for the queue.
2、 如权利要求 1所述的方法, 其中, 还包括步骤: 2. The method according to claim 1, further comprising the steps of:
当所述检测结果为否定时, 占用所述所需的临界资源用于所述第一线 程;  When the detection result is negative, occupying the required critical resource for the first thread;
利用所述占用的用于所述第一线程的临界资源对所述数据执行所述指 定处理。  The specified process is performed on the data using the occupied critical resource for the first thread.
3、 如权利要求 2所述的方法, 其中, 还包括步骤: 3. The method of claim 2, further comprising the steps of:
在对所述数据执行所述指定处理后, 检查所述第一线程的处理等待队 列中是否保存有其它线程发送的数据;  After performing the specifying process on the data, checking whether the data sent by another thread is saved in the processing waiting queue of the first thread;
当检查结果为肯定时, 按照所述第一线程的处理等待队列的优先级从 高到低的顺序, 利用所述占用的用于所述第一线程的临界资源对所述第一 线程的处理等待队列所保存的数据执行所述指定处理;  When the check result is affirmative, processing the first thread by using the occupied critical resource for the first thread according to a priority of processing priority queues of the first thread waiting for the first thread Waiting for the data saved by the queue to perform the specified processing;
当检查结果为否定时, 释放所述占用的用于所述第一线程的临界资源。  When the check result is negative, the occupied critical resource for the first thread is released.
4、 如权利要求 1所述的方法, 其中, 所述发送步骤进一步包括: 当所述检测结果为肯定时, 识别所述数据的优先级; 4. The method according to claim 1, wherein the transmitting step further comprises: identifying a priority of the data when the detection result is affirmative;
将所述数据发送给所述另一线程的与所述数据的所述优先级相对应的 处理等待队列。  The data is sent to a processing wait queue of the other thread that corresponds to the priority of the data.
5、 如权利要求 1所述的方法, 其中, 所述检测步骤进一步包括: 对所述临界资源施加所述第一线程的互斥锁; 5. The method of claim 1, wherein the detecting step further comprises: applying a mutex lock of the first thread to the critical resource;
当施加所述互斥锁失败时, 确定所述临界资源已经被另一线程占用。 When the mutex is failed to be applied, it is determined that the critical resource has been occupied by another thread.
6、 如权利要求 1-5的任意一个所述的方法, 其中, 6. The method according to any one of claims 1 to 5, wherein
所述数据是需要拆分为 ATM信元的 SSSAR报文, 所述指定处理是 AAL2分片处理, 所述临界资源是与发送所述 SSSAR报文的所述 ATM信 元的虚通路连接有关的临界资源,  The data is an SSSAR packet that needs to be split into ATM cells, and the specified processing is AAL2 fragmentation processing, and the critical resource is related to a virtual path connection of the ATM cell that sends the SSSAR message. Critical resource,
或者, 所述数据是需要重组为 SSSAR报文的 ATM信元, 所述指定处 理是 AAL2重组处理,所述临界资源是与接收所述 SSSAR报文的所述 ATM 信元的虚通路连接有关的临界资源。  Or the data is an ATM cell that needs to be reassembled into an SSSAR message, where the specified process is an AAL2 reassembly process, and the critical resource is related to a virtual path connection of the ATM cell that receives the SSSAR message. Critical resources.
7、 一种用于在第一线程中处理数据的装置, 包括: 7. An apparatus for processing data in a first thread, comprising:
检测模块, 用于当所述第一线程接收到需要执行指定处理的数据时, 检测对所述数据执行所述指定处理所需的临界资源是否已经被另一线程占 用;  a detecting module, configured to: when the first thread receives data that needs to perform specified processing, detect whether a critical resource required to perform the specified processing on the data has been occupied by another thread;
发送模块, 用于当检测结果为肯定时, 将所述数据发送给所述另一线 程的处理等待队列。  And a sending module, configured to send the data to a processing waiting queue of the another thread when the detection result is positive.
8、 如权利要求 7所述的装置, 其中, 还包括: 8. The apparatus according to claim 7, further comprising:
占用模块, 用于当所述检测结果为否定时, 占用所述临界资源用于所 述第一线程;  An occupation module, configured to occupy the critical resource for the first thread when the detection result is negative;
执行模块, 用于利用所述占用的用于所述第一线程的临界资源对所述 数据执行所述指定处理。  And an execution module, configured to perform the specified processing on the data by using the occupied critical resource for the first thread.
9、 如权利要求 8所述的装置, 其中, 还包括: 9. The apparatus according to claim 8, further comprising:
检查模块, 用于在对所述数据执行所述指定处理后, 检查所述第一线 程的处理等待队列中是否保存有其它线程发送的数据;  An checking module, configured to check whether data sent by another thread is saved in a processing waiting queue of the first thread after performing the specifying process on the data;
释放模块, 用于当检查结果为否定时, 释放所述占用的用于所述第一 线程的临界资源。  And a release module, configured to release the occupied critical resource for the first thread when the check result is negative.
其中, 所述执行模块还用于当检查结果为肯定时, 按照所述第一线程 的处理等待队列的优先级从高到低的顺序, 利用所述占用的用于所述第一 线程的临界资源对所述第一线程的处理等待队列所保存的数据执行所述指 定处理。 The execution module is further configured to: when the check result is positive, use the occupied threshold for the first thread according to a priority of processing priority queues of the first thread The resource performs the specified processing on the data held by the processing wait queue of the first thread.
10、 如权利要求 7所述的装置, 其中, 所述发送模块进一步包括: 识别模块, 用于当所述检测结果为肯定时, 识别所述数据的优先级; 传递模块, 用于将所述数据发送给所述另一线程的与所述数据的所述 优先级相对应的处理等待队列。 The device of claim 7, wherein the sending module further comprises: an identifying module, configured to: when the detection result is positive, identify a priority of the data; a transmitting module, configured to: Data is sent to the processing queue of the other thread corresponding to the priority of the data.
11、 如权利要求 7所述的装置, 其中, 所述检测模块进一步包括: 施加模块, 用于对所述临界资源施加所述第一线程的互斥锁; 确定模块, 用于当施加所述互斥锁失败时, 确定所述临界资源已经被 另一线程占用。 The device of claim 7, wherein the detecting module further comprises: an applying module, configured to apply a mutual exclusion lock of the first thread to the critical resource; and a determining module, configured to When the mutex fails, it is determined that the critical resource is already occupied by another thread.
12、 如权利要求 7-11的任意一个所述的装置, 其中, 12. The apparatus according to any one of claims 7-11, wherein
所述数据是需要拆分为 ATM信元的 SSSAR报文, 所述指定处理是 AAL2分片处理, 所述临界资源是与发送所述 SSSAR报文的所述 ATM信 元的虚通路连接有关的临界资源,  The data is an SSSAR packet that needs to be split into ATM cells, and the specified processing is AAL2 fragmentation processing, and the critical resource is related to a virtual path connection of the ATM cell that sends the SSSAR message. Critical resource,
或者, 所述数据是需要重组为 SSSAR报文的 ATM信元, 所述指定处理 是 AAL2重组处理,所述临界资源是与接收所述 SSSAR报文的所述 ATM信元 的虚通路连接有关的临界资源。  Or the data is an ATM cell that needs to be reassembled into an SSSAR message, where the specified process is an AAL2 reassembly process, and the critical resource is related to a virtual path connection of the ATM cell that receives the SSSAR message. Critical resources.
13、 一种机器可读存储介质, 其存储机器可执行指令, 当所述机器可 执行指令被执行时使得机器执行权利要求 1-6的任何一个权利要求中的步 骤。 13. A machine readable storage medium storing machine executable instructions which, when executed, cause a machine to perform the steps of any one of claims 1-6.
PCT/CN2011/076552 2011-06-29 2011-06-29 Method and device for processing data by utilizing threads WO2012159309A1 (en)

Priority Applications (2)

Application Number Priority Date Filing Date Title
PCT/CN2011/076552 WO2012159309A1 (en) 2011-06-29 2011-06-29 Method and device for processing data by utilizing threads
CN201180000911.9A CN103608775B (en) 2011-06-29 2011-06-29 Method and device for processing data by using threads

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
PCT/CN2011/076552 WO2012159309A1 (en) 2011-06-29 2011-06-29 Method and device for processing data by utilizing threads

Publications (1)

Publication Number Publication Date
WO2012159309A1 true WO2012159309A1 (en) 2012-11-29

Family

ID=47216552

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2011/076552 WO2012159309A1 (en) 2011-06-29 2011-06-29 Method and device for processing data by utilizing threads

Country Status (2)

Country Link
CN (1) CN103608775B (en)
WO (1) WO2012159309A1 (en)

Families Citing this family (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106293634A (en) * 2015-05-13 2017-01-04 阿里巴巴集团控股有限公司 The method and system that data process
CN108647100A (en) * 2018-04-16 2018-10-12 北京酷我科技有限公司 A kind of method that single thread daily record sends management
CN110221923B (en) * 2019-06-06 2021-06-08 北京字节跳动网络技术有限公司 Data access method, device and equipment
CN112653639B (en) * 2020-12-21 2022-10-14 北京华环电子股份有限公司 IPv6 message fragment recombination method based on multi-thread interactive processing

Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20040216112A1 (en) * 2003-04-23 2004-10-28 International Business Machines Corporation System and method for thread prioritization during lock processing
CN101051281A (en) * 2007-05-16 2007-10-10 杭州华三通信技术有限公司 Method and device for mutual repulsion access of multiple CPU to critical resources

Family Cites Families (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US7676809B2 (en) * 2003-10-09 2010-03-09 International Business Machines Corporation System, apparatus and method of enhancing priority boosting of scheduled threads
US9201703B2 (en) * 2006-06-07 2015-12-01 International Business Machines Corporation Sharing kernel services among kernels

Patent Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20040216112A1 (en) * 2003-04-23 2004-10-28 International Business Machines Corporation System and method for thread prioritization during lock processing
CN101051281A (en) * 2007-05-16 2007-10-10 杭州华三通信技术有限公司 Method and device for mutual repulsion access of multiple CPU to critical resources

Also Published As

Publication number Publication date
CN103608775A (en) 2014-02-26
CN103608775B (en) 2017-02-22

Similar Documents

Publication Publication Date Title
US11765074B2 (en) System and method for facilitating hybrid message matching in a network interface controller (NIC)
KR100823785B1 (en) Methods, apparatus, products, and systems for open loop congestion control in a system fabric
US7391772B2 (en) Network multicasting
US7420969B2 (en) Network switch with a parallel shared memory
US7760646B2 (en) Congestion notification in 3G radio access
JP3210906B2 (en) ATM communication network and its inverse multiplexing method
US6122279A (en) Asynchronous transfer mode switch
US7046681B2 (en) Network switch for routing network traffic
CN1623302B (en) ATM port module with integrated Ethernet switch interface
US7602809B2 (en) Reducing transmission time for data packets controlled by a link layer protocol comprising a fragmenting/defragmenting capability
US20050207436A1 (en) Switching device based on aggregation of packets
US20070171929A1 (en) Queue management in a network processor
US5511076A (en) Method and apparatus to efficiently reuse virtual connections by means of chaser packets
CN101115008A (en) A reputation-based traffic control system, device and method
US20060159102A1 (en) Interworking between cell and packet based networks
CN103608775B (en) Method and device for processing data by using threads
WO2022068633A1 (en) Method and apparatus for sending frame slice
US8661173B2 (en) USB data striping
CN112311448B (en) Satellite network acceleration system based on virtual machine
CN1791069A (en) Input queue packet switch architecture and queue service discipline
WO2009132542A1 (en) A method and an apparatus for message transmission
US6671280B1 (en) Network processor for multiprotocol data flows
US20140233572A1 (en) Handling Method and Device for Cell Concatenation
US7505467B1 (en) Method and apparatus for dynamic bandwidth management for voice traffic in a digital communications network
JP2000253018A (en) ATM priority control IP gateway device, ATM priority control IP routing device, and processing method thereof

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 11866229

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 11866229

Country of ref document: EP

Kind code of ref document: A1