You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The rptr and wptr variables here are missing volatile, so GCC will optimize the while loop in tcp_server_put_byte to a branch and an infinite loop when compiling with -O2. as you can see in this godbolt link.
The text was updated successfully, but these errors were encountered:
Oh dear! Thanks for the report and for analysing what exactly is going on here. If I understand correctly, the tcp_buffer_put_byte function expects some other thread to update rptr and, because it isn't volatile, we get the infinite loop you describe.
Presumably a trivial way to get this effect would be to pass buf is as volatile struct tcp_buf *buf or similar. It's "more volatile" than just the pointer variables (because we are allowing the outside world to change buf->buf as well), but the meaning might be more obvious (and doesn't require us to add annotations to the struct itself).
Oh dear! Thanks for the report and for analysing what exactly is going on here. If I understand correctly, the tcp_buffer_put_byte function expects some other thread to update rptr and, because it isn't volatile, we get the infinite loop you describe.
Yep!
Presumably a trivial way to get this effect would be to pass buf is as volatile struct tcp_buf *buf or similar. It's "more volatile" than just the pointer variables (because we are allowing the outside world to change buf->buf as well), but the meaning might be more obvious (and doesn't require us to add annotations to the struct itself).
Description
The
rptr
andwptr
variables here are missingvolatile
, so GCC will optimize the while loop in tcp_server_put_byte to a branch and an infinite loop when compiling with -O2. as you can see in this godbolt link.The text was updated successfully, but these errors were encountered: