Replies: 10 comments 9 replies
-
Oh, nice 😄 |
Beta Was this translation helpful? Give feedback.
-
hi @dwalend, In relation to the point:
With current implementation, I don´t see issues for concurrent reads, so my question, do you see something pending at Battery level? |
Beta Was this translation helpful? Give feedback.
-
I too think both can be considered safe in their respective assumption sets. The issue I see with the non-synchronized approach is that it breaks code that previously worked/had different assumptions (and that might be OK). There is also another issue - Battery is made a thread-unsafe singleton by this change. If it wasn't a singleton, I could create a per-thread instance and the race would be gone (mitigating on the user side). Also,
I think we cannot handle this differently (empty attribute is a valid attribute). Also, if the user wants to read an integer from an empty file, the code has to blow up, doing something different would hamper debugging in my opinion. However, this reader/writer race shouldn't be an issue for real sysfs in
I thought the same, but stepping through the code in IDE and seeing the file as really empty changed my mind. |
Beta Was this translation helpful? Give feedback.
-
@jabrena I added a test for the race that could happen in |
Beta Was this translation helpful? Give feedback.
-
Oh - you can't presuppose ThreadLocals will be OK. They are an allocation disaster with thread pools on a large scale. Using them forces a possibly-inappropriate system-level decision on everyone using the library. Probably not a big problem for EV3, but it forces a single solution. In particular I won't be able to use cats IO. One sane way to use these things multithreaded is likely to read from the OS and update a volatile value in the JVM with a task. If that thread is from a pool then ThreadLocal starts allocating per thread, out of the developer's control. |
Beta Was this translation helpful? Give feedback.
-
We could do an internal lock on read() and close() instead of synchronized on the two methods. That offers some protection vs. a diabolical problem - someone else using DataChannelRereader as their own lock - that never happens. Another alternative is to allocate something new for every read - Sysfs was already doing that. We could set up our own reading thread, and put whatever we read in a volatile. That seems heavy-handed, premature optimization. Most everything else is systemic and we should avoid doing it in a library. |
Beta Was this translation helpful? Give feedback.
-
Ev3LedTest is a bit broken; it takes advantage of Sysfs's public static boolean writeString(final String filePath, final String value) {
if (file.canWrite()) {
// evaluating to false and, well, not really testing anything. |
Beta Was this translation helpful? Give feedback.
-
#781 in for preliminary review. |
Beta Was this translation helpful? Give feedback.
-
And I updated #778 |
Beta Was this translation helpful? Give feedback.
-
Today, I will be off. Family matters |
Beta Was this translation helpful? Give feedback.
-
#765
Beta Was this translation helpful? Give feedback.
All reactions