Ring buffer usage & whether the operation has BUG?

1. Use ring buffers to exchange data, threadWrite-> buf-> threadRead
threadWrite {

memcpy(buf[pushCount & mask], value, size);
pushCountPP;
...

}

threadRead {

...

}

if mask = = 2, pushCount accumulates from 0
when pushCount = 0
pushCount & mask = = 0
when pushCount = 1
pushCount & mask = = 0
when pushCount = 2
pushCount & mask = = 2

is there a problem? the second position of the array is not written, and the first position is written twice

.

2. Is there any special requirement for the mask mask of the ring queue, such as parity and so on? please answer

.
Mar.21,2021

if you use & , the mask mask must satisfy $2 ^ n-1 $$

The

ring buffer actually uses a residual operation to ensure that it does not explode. If you use the normal balance % , then there is no requirement for mask. If you use bitwise and & , only if mask satisfies the above conditions, all binary bits are 1 , which can be equivalent to the remainder.

  • Read the memory of other processes

    The scenario is as follows: process 1 writes some data by three-party code in memory mem. the existing code cannot be modified, but the existing code can be read within the process. the requirement is that the data needs to be shared and read by mult...

    Mar.28,2021
  • The problem of real-time stream data collection

    problem description you need to implement a distributed system that collects logs and data on a value data server. Is there a good solution without using messaging frameworks such as Kafka? ...

    Dec.04,2021
  • MacOS 10.13 installation using brew bochs cannot be run

    macOS 10.13 cannot be executed after installing bochs using brew install bochs. The following error is reported. I have manually installed gtk+,sdl,sdl2 and other dependent packages, and correctly configured the configuration file of bochsrc. What is th...

    Jun.01,2022
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1be63ff-317d6.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1be63ff-317d6.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?