- Notifications
You must be signed in to change notification settings - Fork46
-
BetaWas this translation helpful?Give feedback.
All reactions
Replies: 10 comments 9 replies
-
Oh, nice 😄 |
BetaWas this translation helpful?Give feedback.
All reactions
-
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? |
BetaWas this translation helpful?Give feedback.
All reactions
-
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. |
BetaWas this translation helpful?Give feedback.
All reactions
-
I'm not sure about synchronizing DataChannelRewriter. As we now know that concurrent reads/writes are problematic, I'd probably be OK with letting that break. |
BetaWas this translation helpful?Give feedback.
All reactions
-
@jabrena I added a test for the race that could happen in |
BetaWas this translation helpful?Give feedback.
All reactions
-
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. |
BetaWas this translation helpful?Give feedback.
All reactions
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
I was a bit worried about it (mentioned in javadoc). It then seems that ThreadLocals are KO. I see the following remaining options with regards to Battery:
|
BetaWas this translation helpful?Give feedback.
All reactions
-
hi@dwalend, what other alternatives do, we have apart of |
BetaWas this translation helpful?Give feedback.
All reactions
-
@JakubVanek, |
BetaWas this translation helpful?Give feedback.
All reactions
-
It does partially generalize, I think. If we solve this for Battery, other devices should follow easily. For classes where constructors are public (/non-singletons), thread ownership could be additionally modelled by hiding the reference to the device instance from other threads (i.e. how DataChannelRereader worked in old DataChannelRereaderConcurrencyTest). For singletons, all threads have access to one common reference, a situation that seems harder to solve. |
BetaWas this translation helpful?Give feedback.
All reactions
-
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. |
BetaWas this translation helpful?Give feedback.
All reactions
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
Hi@dwalend It is better, if we try with this alternative:
The another alternative increase the complexity. Lets try with the locks. :) |
BetaWas this translation helpful?Give feedback.
All reactions
👍 1
-
While my opinion is not based on numbers, in some cases this might end up slower than before. Doing this in a separate thread would add periodic context switches (these might happen due to JIT/GC too though) and it could make the data out-of-date (the thread is likely not going to be scheduled each millisecond). |
BetaWas this translation helpful?Give feedback.
All reactions
👍 1
-
synchronized is a fine answer, especially if we can't measure a performance hit after JIT and hotspot kick in. Hotspot should be able to optimize away the lock. |
BetaWas this translation helpful?Give feedback.
All reactions
-
Details were easy to find, but are maybe a bit dated - 2008:https://wiki.openjdk.java.net/display/HotSpot/Synchronization "Only the first lock acquisition performs an atomic compare-and-swap to install an ID of the locking thread into the header word. The object is then said to be biased towards the thread. Future locking and unlocking of the object by the same thread do not require any atomic operation or an update of the header word. Even the lock record on the stack is left uninitialized as it will never be examined for a biased object." |
BetaWas this translation helpful?Give feedback.
All reactions
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
Ev3LedTest is a bit broken; it takes advantage of Sysfs's publicstaticbooleanwriteString(finalStringfilePath,finalStringvalue) {if (file.canWrite()) {// evaluating to false and, well, not really testing anything. |
BetaWas this translation helpful?Give feedback.
All reactions
👍 1
-
#781 in for preliminary review. |
BetaWas this translation helpful?Give feedback.
All reactions
-
And I updated#778 |
BetaWas this translation helpful?Give feedback.
All reactions
-
Today, I will be off. Family matters |
BetaWas this translation helpful?Give feedback.
All reactions
👍 1