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

When does postingState.isPosting become false in the post(Object event) method? #669

Open
sreramk opened this issue Jun 11, 2021 · 3 comments

Comments

@sreramk
Copy link

sreramk commented Jun 11, 2021

The variable postingState is local to the thread retrieving it.

if (!postingState.isPosting) {

Therefore, it must always be unique to each concurrent (or parallel) thread running the same method.

When does the value of the if statement become false in the above condition? Assuming it does become false, why doesn't this cause any race conditions? Given that there are no locks used, and it is also not an atomic variable.

@sreramk sreramk changed the title When does postingState.isPosting become false in the post(...) method? When does postingState.isPosting become false in the post(Object event) method? Jun 11, 2021
@andob
Copy link
Contributor

andob commented Jun 11, 2021

as far as I understand the code:

When does the value of the if statement become false in the above condition?
before the if statement isPosting will always be false. seems like a safeguard.

Assuming it does become false, why doesn't this cause any race conditions?
well it probably would cause race conditions in that case.

however, if you look at cancelEventDelivery you'll see this variable is used in order to ensure some preconditions. so it's not useless.

@sreramk
Copy link
Author

sreramk commented Jun 11, 2021

Thanks for clarifying. I was trying to understand the code and that part was confusing. Even if it does not have any performance impact, removing the condition statement (assuming there is no other reason for having it) could make that part less confusing.

@tomridder
Copy link

Thanks for clarifying. I was trying to understand the code and that part was confusing. Even if it does not have any performance impact, removing the condition statement (assuming there is no other reason for having it) could make that part less confusing.

race condition will appear with shared variable ,but PostingThreadState variable is in ThreadLocal.so it is unique for every thread , not a shared variable.
so it won't cause race condition.

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

No branches or pull requests

3 participants