CN113641506A - Multi-protocol synchronization barrier method and device based on Golang language - Google Patents

Multi-protocol synchronization barrier method and device based on Golang language Download PDF

Info

Publication number
CN113641506A
CN113641506A CN202110752489.8A CN202110752489A CN113641506A CN 113641506 A CN113641506 A CN 113641506A CN 202110752489 A CN202110752489 A CN 202110752489A CN 113641506 A CN113641506 A CN 113641506A
Authority
CN
China
Prior art keywords
pipeline
protocol
coroutine
blocked
pipe
Prior art date
Legal status (The legal status 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 status listed.)
Pending
Application number
CN202110752489.8A
Other languages
Chinese (zh)
Inventor
苏楷
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Tibet Ningsuan Technology Group Co ltd
Original Assignee
Dilu Technology Co Ltd
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 Dilu Technology Co Ltd filed Critical Dilu Technology Co Ltd
Priority to CN202110752489.8A priority Critical patent/CN113641506A/en
Publication of CN113641506A publication Critical patent/CN113641506A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR 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
    • G06F9/522Barrier synchronisation
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR 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/54Interprogram communication
    • G06F9/544Buffers; Shared memory; Pipes

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Communication Control (AREA)

Abstract

The invention discloses a multi-protocol synchronous barrier method and a device based on Golang language, wherein the method comprises the following steps: initializing a synchronous barrier structure body; the synchronization barrier structure comprises a first pipe and a second pipe; wherein, the process that the synchronous barrier structure body carries out the synchronous barrier includes: the former co-routine operation is carried out, a signal is sent to the first pipeline after the first pipeline is read, and the first pipeline is blocked; the latter protocol runs, after reading the signal sent by the former protocol in the first pipeline, the former protocol is awakened at the first pipeline and blocked at the second pipeline, and the latter protocol is blocked at the first pipeline; after the latter protocol is awakened at the first pipeline, the former protocol and the latter protocol are blocked at the second pipeline together until the second pipeline is closed, and all the protocols blocked at the second pipeline are awakened. By adopting the technical scheme, the common blocking and synchronous awakening of the multiple coroutines are achieved, and simple, convenient and efficient coroutine synchronization is realized.

Description

Multi-protocol synchronization barrier method and device based on Golang language
Technical Field
The invention relates to the technical field of parallel computing, in particular to a multi-protocol synchronization barrier method and device based on Golang language.
Background
Synchronization Barrier (Barrier) is a synchronization method in parallel computing, for a group of processes or threads, one synchronization Barrier in a program means that any thread/process must wait until after execution until all threads/processes reach this point before the context can continue to be executed.
In other computer languages, there are common or mature methods for implementing a synchronization barrier, but there is no simple, convenient and efficient scheme for implementing a synchronization barrier in Golang language.
Disclosure of Invention
The purpose of the invention is as follows: the invention provides a multi-protocol synchronization barrier method and device based on Golang language, and aims to realize a simple, convenient and efficient synchronization method.
The technical scheme is as follows: the invention provides a multi-protocol synchronization barrier method based on Golang language, which comprises the following steps:
initializing a synchronous barrier structure body; the synchronization barrier structure comprises a first pipe and a second pipe;
wherein, the process that the synchronous barrier structure body carries out the synchronous barrier includes:
the former co-routine operation is carried out, a signal is sent to the first pipeline after the first pipeline is read, and the first pipeline is blocked;
the latter protocol runs, after reading the signal sent by the former protocol in the first pipeline, the former protocol is awakened at the first pipeline and blocked at the second pipeline, and the latter protocol is blocked at the first pipeline;
after the latter protocol is awakened at the first pipeline, the former protocol and the latter protocol are blocked at the second pipeline together until the second pipeline is closed, and all the protocols blocked at the second pipeline are awakened.
Specifically, when each coroutine runs, the selector reads the first pipeline, if data exists in the first pipeline, the current coroutine quantity is increased by one, and whether the current coroutine quantity reaches the coroutine total number is judged; and when the current coroutine quantity reaches the coroutine total quantity, closing the second pipeline.
Specifically, the first pipeline and the second pipeline are both buffer-free pipelines.
Specifically, each coroutine runs, after sending a signal to the first pipeline, the second pipeline is read.
The invention also provides a multi-protocol synchronous barrier device based on Golang language, which comprises: an initialization unit and a synchronization unit, wherein:
the initialization unit is used for initializing the synchronous barrier structure body; the synchronization barrier structure comprises a first pipe and a second pipe;
the synchronization unit is configured to perform a synchronization barrier process, and includes:
the former co-routine operation is carried out, a signal is sent to the first pipeline after the first pipeline is read, and the first pipeline is blocked;
the latter protocol runs, after reading the signal sent by the former protocol in the first pipeline, the former protocol is awakened at the first pipeline and blocked at the second pipeline, and the latter protocol is blocked at the first pipeline;
after the latter protocol is awakened at the first pipeline, the former protocol and the latter protocol are blocked at the second pipeline together until the second pipeline is closed, and all the protocols blocked at the second pipeline are awakened.
The device comprises a selector, a counting unit and a processing unit, wherein the counting unit is used for reading a first pipeline when each coroutine runs, if data exists in the first pipeline, the current coroutine quantity is increased by one, and whether the current coroutine quantity reaches the coroutine total number is judged;
and when the current coroutine quantity reaches the coroutine total quantity, closing the second pipeline.
Specifically, the first pipeline and the second pipeline are both buffer-free pipelines.
Specifically, each coroutine runs, after sending a signal to the first pipeline, the second pipeline is read.
Has the advantages that: compared with the prior art, the invention has the following remarkable advantages: the method has the advantages that the multi-protocol common blocking and synchronous awakening are achieved by using the pipeline and the selector in the Golang language and through the mode of sending signals and reading the pipeline, and simple, convenient and efficient protocol synchronization is achieved.
Drawings
Fig. 1 is a schematic flow chart of a multiprotocol synchronization barrier method based on Golang language provided in the present invention.
Detailed Description
The technical scheme of the invention is further explained by combining the attached drawings.
Fig. 1 is a schematic flow chart of a multi-protocol synchronization barrier method based on Golang language according to the present invention.
The invention provides a multi-protocol synchronous barrier method based on Golang language, which firstly defines a synchronous barrier structure body, wherein the synchronous barrier structure body can comprise a first pipeline and a second pipeline, and the total number of protocols and the current number of protocols. The synchronization barrier structure may be initialized when a synchronization barrier function is to be performed soon.
In the embodiment of the present invention, the first pipeline and the second pipeline may be both buffer-free pipelines.
In one embodiment, a buffer-less pipe refers to a pipe without a buffer into which an element is placed and which enters a blocked state immediately after the element is placed, and from which the element must be removed by a read operation or the like before the element can be placed further.
In an embodiment of the present invention, the process of executing the synchronization barrier by the synchronization barrier structure includes:
the former co-routine operation is carried out, a signal is sent to the first pipeline after the first pipeline is read, and the first pipeline is blocked;
the latter protocol runs, after reading the signal sent by the former protocol in the first pipeline, the former protocol is awakened at the first pipeline and blocked at the second pipeline, and the latter protocol is blocked at the first pipeline;
after the latter protocol is awakened at the first pipeline, the former protocol and the latter protocol are blocked at the second pipeline together until the second pipeline is closed, and all the protocols blocked at the second pipeline are awakened.
In the embodiment of the invention, when each coroutine runs, the selector reads the first pipeline, if data exists in the first pipeline, the current coroutine quantity is increased by one, and whether the current coroutine quantity reaches the coroutine total number is judged;
and when the current coroutine quantity reaches the coroutine total quantity, closing the second pipeline.
In specific implementation, the operating coroutine 1 sends a signal to the first pipeline, namely, the process of writing in the first pipeline, and returns a pointer of the synchronous barrier structure, and due to the characteristic of the unbuffered pipeline, the coroutine 1 blocks the first pipeline after sending the signal, and the coroutine 1 cannot be awakened until other coroutines read the signal sent by the coroutine 1 from the first pipeline, namely, when reading operation is performed, and the coroutine 1 is taken away from the first pipeline.
In a specific implementation, when the coroutine 1 (the previous coroutine) is blocked in the first pipeline, the coroutine 2 (the next coroutine) can read a signal of the coroutine 1 in the first pipeline, take the coroutine 1 out of the first pipeline, then the coroutine 1 enters the second pipeline and is blocked in the second pipeline, and the coroutine 2 can send a signal to the first pipeline again and is blocked in the first pipeline.
In an implementation, when the coroutine 2 (the latter coroutine) is blocked in the first pipeline, the coroutine 3 reads a signal of the coroutine 2 in the first pipeline, takes the coroutine 2 out of the first pipeline, then the coroutine 2 and the coroutine 1 are blocked in the second pipeline together, and the coroutine 3 sends a signal to the first pipeline and is blocked in the first pipeline. In this way, after passing through the first pipeline, coroutines 1, 2, 3, … …, n are blocked in the second pipeline together, and after waiting for all to be awakened and activated, the subsequent operations are executed together.
In a specific implementation, the selector (select) may read the first pipe each time the coroutine runs, and when the first pipe has data, the current coroutine number is increased by one, for example, when coroutine 1 blocks the first pipe, the current coroutine number is counted as 1, and when coroutine 2 blocks the first pipe, the current coroutine number is counted as 2. When the number of the current coroutine quantity reaches the coroutine total number n, the coroutine n closes the second pipeline, at the moment, the first n-1 coroutines blocked at the second pipeline are all awakened and activated, the subsequent operation is executed, the coroutine n can be read, and the coroutine n is awakened and activated.
In the embodiment of the invention, when each coroutine runs, the second pipeline is read after the signal is sent to the first pipeline.
The invention also provides a multi-protocol synchronous barrier device based on Golang language, which comprises: an initialization unit and a synchronization unit, wherein:
the initialization unit is used for initializing the synchronous barrier structure body; the synchronization barrier structure comprises a first pipe and a second pipe;
the synchronization unit is configured to perform a synchronization barrier process, and includes:
the former co-routine operation is carried out, a signal is sent to the first pipeline after the first pipeline is read, and the first pipeline is blocked;
the latter protocol runs, after reading the signal sent by the former protocol in the first pipeline, the former protocol is awakened at the first pipeline and blocked at the second pipeline, and the latter protocol is blocked at the first pipeline;
after the latter protocol is awakened at the first pipeline, the former protocol and the latter protocol are blocked at the second pipeline together until the second pipeline is closed, and all the protocols blocked at the second pipeline are awakened.
In the embodiment of the invention, the multiple protocol synchronous barrier device based on the Golang language further comprises a counting unit, wherein when each protocol runs, the selector reads the first pipeline, if data exists in the first pipeline, the current protocol quantity is increased by one, and whether the current protocol quantity reaches the total protocol quantity is judged;
and when the current coroutine quantity reaches the coroutine total quantity, closing the second pipeline.
In the embodiment of the invention, the first pipeline and the second pipeline are both buffer-free pipelines.
In the embodiment of the invention, when each coroutine runs, the second pipeline is read after the signal is sent to the first pipeline.

Claims (8)

1. A multi-protocol synchronization barrier method based on Golang language is characterized by comprising the following steps:
initializing a synchronous barrier structure body; the synchronization barrier structure comprises a first pipe and a second pipe;
wherein, the process that the synchronous barrier structure body carries out the synchronous barrier includes:
the former co-routine operation is carried out, a signal is sent to the first pipeline after the first pipeline is read, and the first pipeline is blocked;
the latter protocol runs, after reading the signal sent by the former protocol in the first pipeline, the former protocol is awakened at the first pipeline and blocked at the second pipeline, and the latter protocol is blocked at the first pipeline;
after the latter protocol is awakened at the first pipeline, the former protocol and the latter protocol are blocked at the second pipeline together until the second pipeline is closed, and all the protocols blocked at the second pipeline are awakened.
2. The Golang language-based multipass synchronization barrier method according to claim 1, comprising:
when each coroutine runs, the selector reads the first pipeline, if data exists in the first pipeline, the current coroutine quantity is increased by one, and whether the current coroutine quantity reaches the coroutine total number is judged;
and when the current coroutine quantity reaches the coroutine total quantity, closing the second pipeline.
3. The Golang language-based multipass synchronization barrier method of claim 2, wherein the first pipe and the second pipe are both unbuffered pipes.
4. The Golang language-based multipass synchronization barrier method of claim 3, wherein each of the multipaths is run while reading the second pipe after sending a signal to the first pipe.
5. A multi-protocol synchronization barrier device based on Golang language is characterized by comprising: an initialization unit and a synchronization unit, wherein:
the initialization unit is used for initializing the synchronous barrier structure body; the synchronization barrier structure comprises a first pipe and a second pipe;
the synchronization unit is configured to perform a synchronization barrier process, and includes:
the former co-routine operation is carried out, a signal is sent to the first pipeline after the first pipeline is read, and the first pipeline is blocked;
the latter protocol runs, after reading the signal sent by the former protocol in the first pipeline, the former protocol is awakened at the first pipeline and blocked at the second pipeline, and the latter protocol is blocked at the first pipeline;
after the latter protocol is awakened at the first pipeline, the former protocol and the latter protocol are blocked at the second pipeline together until the second pipeline is closed, and all the protocols blocked at the second pipeline are awakened.
6. The Golay language-based multiprotocol synchronization barrier apparatus according to claim 5, further comprising a counting unit, wherein when each coroutine is running, the selector reads the first pipe, if there is data in the first pipe, the current coroutine number is increased by one, and determines whether the current coroutine number reaches a coroutine total number;
and when the current coroutine quantity reaches the coroutine total quantity, closing the second pipeline.
7. The Golang language-based multipass synchronization barrier apparatus of claim 6, wherein the first pipe and the second pipe are both unbuffered pipes.
8. The Golang-based multipass synchronization barrier apparatus of claim 7, wherein each of the multipaths is run while reading the second pipe after sending a signal to the first pipe.
CN202110752489.8A 2021-07-02 2021-07-02 Multi-protocol synchronization barrier method and device based on Golang language Pending CN113641506A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202110752489.8A CN113641506A (en) 2021-07-02 2021-07-02 Multi-protocol synchronization barrier method and device based on Golang language

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202110752489.8A CN113641506A (en) 2021-07-02 2021-07-02 Multi-protocol synchronization barrier method and device based on Golang language

Publications (1)

Publication Number Publication Date
CN113641506A true CN113641506A (en) 2021-11-12

Family

ID=78416595

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202110752489.8A Pending CN113641506A (en) 2021-07-02 2021-07-02 Multi-protocol synchronization barrier method and device based on Golang language

Country Status (1)

Country Link
CN (1) CN113641506A (en)

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20070016905A1 (en) * 2005-07-12 2007-01-18 Microsoft Corporation Blocking local sense synchronization barrier
WO2017063521A1 (en) * 2015-10-15 2017-04-20 中兴通讯股份有限公司 Coroutine monitoring method and apparatus
CN110716755A (en) * 2019-10-14 2020-01-21 浙江诺诺网络科技有限公司 Thread exit method, device, equipment and readable storage medium

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20070016905A1 (en) * 2005-07-12 2007-01-18 Microsoft Corporation Blocking local sense synchronization barrier
CN101501643A (en) * 2005-07-12 2009-08-05 微软公司 Blocking local sense synchronization barrier
WO2017063521A1 (en) * 2015-10-15 2017-04-20 中兴通讯股份有限公司 Coroutine monitoring method and apparatus
CN110716755A (en) * 2019-10-14 2020-01-21 浙江诺诺网络科技有限公司 Thread exit method, device, equipment and readable storage medium

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
九卷: "Golang基础(9):goroutine协程和channel通道", pages 1 - 3, Retrieved from the Internet <URL:https://www.cnblogs.com/jiujuan/p/11723586.html> *

Similar Documents

Publication Publication Date Title
JP4233893B2 (en) Instruction tracing in data processing systems.
CN100590655C (en) Instruction parser, graphic processing unit and method thereof
US8698756B2 (en) Interrupt reduction method in touch screen controller
US6760835B1 (en) Instruction branch mispredict streaming
WO2013173550A1 (en) Fusing conditional write instructions having opposite conditions in instruction processing circuits, and related processor systems, methods, and computer-readable media
CN106844017A (en) The method and apparatus that event is processed for Website server
KR20150129316A (en) Eliminating redundant synchronization barriers in instruction processing circuits, and related processor systems, methods, and computer-readable media
CN102298565A (en) Method for decoding and triggering asynchronous serial bus signals
US7945765B2 (en) Method and structure for asynchronous skip-ahead in synchronous pipelines
US7356674B2 (en) Method and apparatus for fetching instructions from the memory subsystem of a mixed architecture processor into a hardware emulation engine
WO2015184908A1 (en) Reverse debug method, device and debugger
US11520580B2 (en) Processor with instruction iteration
CN113641506A (en) Multi-protocol synchronization barrier method and device based on Golang language
CN110460495B (en) Water level propelling method and device, computing node and storage medium
CN1161693C (en) One-step debugging card unit with PCJ interface and its operation process
GB2541400A (en) Tracing of exception handling events
US10402201B2 (en) Method and apparatus for detecting memory conflicts using distinguished memory addresses
CN116627495A (en) Information interaction method, system, device, equipment and medium
US7310260B2 (en) High performance register accesses
US8125489B1 (en) Processing pipeline with latency bypass
US9983932B2 (en) Pipeline processor and an equal model compensator method and apparatus to store the processing result
CN116841614B (en) Sequential vector scheduling method under disordered access mechanism
WO2019191643A1 (en) Register reconfiguration using direct descriptor fetch for efficient multi-pass processing of computer vision and video encoding applications
CN106775612A (en) Interrupt the method and device of network equipment background process
CN105393211B (en) The system and method for asynchronous processor with pipeline system arithmetic logic unit

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
TA01 Transfer of patent application right
TA01 Transfer of patent application right

Effective date of registration: 20230306

Address after: 851414 11th Floor, Liuwu Building, Liuwu New District, Lhasa, Tibet Autonomous Region

Applicant after: Tibet ningsuan Technology Group Co.,Ltd.

Address before: Floor 11, building A1, zone a, Huizhi science and Technology Park, No. 8, Hengtai Road, Qixia District, Nanjing, Jiangsu 210033

Applicant before: DILU TECHNOLOGY Co.,Ltd.