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
- Summary
- Abstract
- Description
- Claims
- Application Information
AI Technical Summary
Problems solved by technology
Method used
Examples
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).
PUM
Abstract
Description
Claims
Application Information
- R&D Engineer
- R&D Manager
- IP Professional
- Industry Leading Data Capabilities
- Powerful AI technology
- Patent DNA Extraction
Browse by: Latest US Patents, China's latest patents, Technical Efficacy Thesaurus, Application Domain, Technology Topic, Popular Technical Reports.
© 2024 PatSnap. All rights reserved.Legal|Privacy policy|Modern Slavery Act Transparency Statement|Sitemap|About US| Contact US: help@patsnap.com