Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CircleBuffer code thread security #2002

Open
Mxiaoyu opened this issue Nov 2, 2020 · 0 comments
Open

CircleBuffer code thread security #2002

Mxiaoyu opened this issue Nov 2, 2020 · 0 comments

Comments

@Mxiaoyu
Copy link

@Mxiaoyu Mxiaoyu commented Nov 2, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant
You can’t perform that action at this time.