serenity-rs / poise

Discord bot command framework for serenity, with advanced features like edit tracking and flexible argument parsing
MIT License
644 stars 114 forks source link

Atomics - Should this be fetch_add? #245

Closed c-git closed 7 months ago

c-git commented 7 months ago

I was reading one of the examples and I saw what looked like code that could result in a race condition but I haven't worked with atomics much so I may be mistaken. I'm just raising it in case someone who knows more than me could take a look. Based on my understanding this code could read the value increment it and then before it writes it back it gets incremented somewhere else and the increment is lost. Might be better to use fetch_add to increment the value in an "atomic" way. Let me know if that makes sense I should be able to do a PR quickly to fix it.

kangalio commented 7 months ago

Ah, that sounds correct. Yeah, feel free to make a PR :+1:

c-git commented 7 months ago

Great created the PR, as I'd already tried making the changes. Still need to test it.