Multi-thread data transmission method

A data transmission method and multi-threaded technology, applied in the multi-threaded data transmission field of multi-threaded access, can solve problems such as program errors, lower system processing performance, and insecurity, and achieve the effect of improving performance

Inactive Publication Date: 2017-01-25
COLASOFT
View PDF4 Cites 0 Cited by
  • Summary
  • Abstract
  • Description
  • Claims
  • Application Information

AI Technical Summary

Problems solved by technology

[0002] Generally, in multi-thread communication, there will be some access to critical resources (multiple threads may be accessed at the same time), because critical resources are public, if they are read and written by multiple threads at the same time, critical resources will become a kind of The unknown state is not safe, and it will cause inexplicable errors in the program. Therefore, when the program uses critical resources, it often uses thread locks to ensure that access to critical resources is safe and controllable. Thread locks are used to ensure that there is only one at any time. Threads to operate critical resources; but this mechanism will cause other threads to process the waiting state, thereby reducing system processing performance

Method used

the structure of the environmentally friendly knitted fabric provided by the present invention; figure 2 Flow chart of the yarn wrapping machine for environmentally friendly knitted fabrics and storage devices; image 3 Is the parameter map of the yarn covering machine
View more

Examples

Experimental program
Comparison scheme
Effect test

specific Embodiment 1

[0017] A multi-thread data transmission method, the specific method is:

[0018] When initializing the system, apply for a continuous memory space that can hold N pointers; said N=2 m , m is an integer greater than or equal to 1; each pointer position is a unit, and N pointer positions form an array space dataPtrArray; the pointer points to the user data address;

[0019] Two integer values ​​are defined: writePos and readPos; wherein, writePos represents the position where the data writing thread is currently about to write the array space; readPos represents the position where the data reading thread is currently about to read data from the array space; If the data is written successfully, the writePos value will be incremented; if the data is read successfully, the readPos value will be incremented, and the pointer value of the successfully read array space position will be cleared. After clearing, the writing thread will find that this position is zero , the new user poin...

specific Embodiment 2

[0023] On the basis of specific embodiment 1, the method also includes: when writing data, using Intel's lock bus technology, in an atomic manner, simultaneously judging whether the writing position is empty, if it is empty, then writing, if If it is not empty, it means that the queue is full, and the writing thread is stuck waiting:

[0024] void* dataPtr is a data pointer that needs to be written into the queue,

[0025] do {

[0026] uint32_t writeLocation = _sync_fetch_and_add(&writePos,1);

[0027] uint64_t* writePtr = (uint64_t*)dataPtrArray[PosMask&writeLocation];

[0028] if(__sync_bool_compare_and_swap(writePtr,0,(uint64_t)dataPtr))

[0029] {

[0030] notifyRead();

[0031] return true; / / write successfully

[0032]}

[0033] else

[0034] {

[0035] wait();

[0036]}

[0037]}

[0038] When reading data, Intel's lock bus technology is used to atomically determine whether the read position is empty. If it is not empty, the read returns and the read position ...

specific Embodiment 3

[0053] On the basis of the specific embodiment 1 or 2, in the memory space, each 8 bytes is a unit. The memory space is 8 bytes, that is, a uint64_t as a unit, which can store the value of sizeof(void*) under any system, that is, store the value of a pointer (the longest pointer is a uint64_t).

the structure of the environmentally friendly knitted fabric provided by the present invention; figure 2 Flow chart of the yarn wrapping machine for environmentally friendly knitted fabrics and storage devices; image 3 Is the parameter map of the yarn covering machine
Login to view more

PUM

No PUM Login to view more

Abstract

The invention provides a multi-thread data transmission method. Two integer values including write Pos and read Pos are defined, wherein the write Pos refers to the current position of a data writing thread for writing data into an array space, and the read Pos refers to the current position of a data reading thread for reading the data from the array space. The write Pos value is automatically increased when the data are successfully written, and the read Pos value is automatically increased when the data are successfully read. An integer mask Pos Mask is defined, and the value of the integer mask Pos Mask is N-1. The position of the actual array space for currently writing and reading the data is determined by AND operation of the value of the Pos Mask and values of the read-write positions, namely, the current writing position is data PtrArray [write Pos &Pos Mask], and the reading position is data PtrArray [read Pos &Pos Mask]. Data transmission between two threads can be realized, namely, a queue container as a critical resource is accessed in an unlocked manner, and performance is greatly improved.

Description

technical field [0001] The invention relates to a multi-thread data transmission method, in particular to a multi-thread data transmission method suitable for multi-thread communication and multi-thread access. Background technique [0002] Generally, in multi-thread communication, there will be some access to critical resources (multiple threads may be accessed at the same time), because critical resources are public, if they are read and written by multiple threads at the same time, critical resources will become a kind of The unknown state is not safe, and it will cause inexplicable errors in the program. Therefore, when the program uses critical resources, it often uses thread locks to ensure that access to critical resources is safe and controllable. Thread locks are used to ensure that there is only one at any time. Threads operate critical resources; however, this mechanism will cause other threads to process wait states, thereby reducing system processing performance...

Claims

the structure of the environmentally friendly knitted fabric provided by the present invention; figure 2 Flow chart of the yarn wrapping machine for environmentally friendly knitted fabrics and storage devices; image 3 Is the parameter map of the yarn covering machine
Login to view more

Application Information

Patent Timeline
no application Login to view more
Patent Type & Authority Applications(China)
IPC IPC(8): G06F9/54
CPCG06F9/544
Inventor 罗鹰黄江林康
Owner COLASOFT
Who we serve
  • R&D Engineer
  • R&D Manager
  • IP Professional
Why Eureka
  • Industry Leading Data Capabilities
  • Powerful AI technology
  • Patent DNA Extraction
Social media
Try Eureka
PatSnap group products