Skip to content

CircleBuffer code thread security  #2002

@Mxiaoyu

Description

@Mxiaoyu
public boolean writeToCharBuffer(char c) {
    boolean result = false;
    // if we can write to the buffer
    if (_readable_data.get() < _buffer_size) {
      // write to buffer
      _buffer[getTrueIndex(_write_index)] = c;
      _readable_data.incrementAndGet();
      _write_index++;
      result = true;
    }
    return result;
  }

thread 1 and thread 2 execute "_buffer[getTrueIndex(_write_index)] = c;" At the same time,the result is not definite.
How about this issue? Or I missed this code.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions