-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Add one more semaphore-related function. #745
base: master
Are you sure you want to change the base?
Conversation
Doing a blocking wait inside a syslock sounds a bit dangerous to me. The whole thing looks a bit unsafe in general. Are you sure that you need a binary semaphore? If your control thread blocks somehow while the imu keeps giving samples something strange is going on... |
Hey Benjamin, thanks for fast turnaround:
Nothing dangerous here, this is exactly how bldc/ChibiOS_3.0.5/os/rt/src/chsem.c Lines 238 to 240 in 68094e9
Agreed with the sentiment but there is no reason not to be defensive, binary semaphore semantics will strictly make Float package more resilient. In practice I've only seen 0 or 1 overruns total. 1 overrun I've seen was happening during start of the Float package because the callback is registered before the Float pkg thread is started. |
More resilient against what? To me it looks like the new suspicious function is vastly more likely to cause trouble than a possible overrun (an overrun that can't happen for no reason btw).
What about starting the thread first and then registering the callback? The thread can even start by waiting for the semaphore, so that nothing is done before new data is available if you care about the very first sample. |
I mean it's threading, it's really hard to reason about. As an example there might be another high priority thread that hogs the CPU and because of this the Float thread doesn't get to run in time to process the IMU data. It might be the case that there are no threads like that currently in the codebase. Yet having this functionality future-proofs things. Another thing to consider is that having a tool that semantically matches your needs is important. In the end you're the owner so I'll follow your opinions on this but I kindly ask you to consider the arguments above.
I'd be happy to address any specific concerns you have, if any. I'm not sure if it's possible to write unit tests against things such as locking but I could give it a shot if you can point me to an example.
Yes totally, that is the way to go I think. |
The new `sem_drain_and_wait_timeout` effectively achieves binary semaphore semantics without relying on `ch_binary_semaphore`. `time_to_ticks` is necessary to pass the correct timeout values to `sem_wait_to` and `sem_drain_and_wait_timeout`
Add
sem_drain_and_wait_timeout
andtime_to_ticks
functions to lispBM.The new
sem_drain_and_wait_timeout
effectively achieves binarysemaphore semantics without relying on
ch_binary_semaphore
type.It's used in Float package in the other PR that I just sent out.
time_to_ticks
is necessary to pass the correct timeout values tosem_wait_to
andsem_drain_and_wait_timeout