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
synchronized blocks are not allowed in BTrace. This makes it very difficult to write thread-safe code. For example, the following code snippet adds a key-value pair to a map if the key is not already in the map. BTraceUtils.newHashMap() returns a synchronized HashMap. However, there is no way to safely write the following code. Two threads can see that map.contains(key) returns false and both threads will call map.put(key, value) with two different values.
Map map = BTraceUtils.newHashMap();
if (!map.contains(key))
map.put(key, value);
else
value = map.get(key);
A synchronized block around contains(), put() and get() calls is needed.
A simple fix would be to provide concurrent data structures or APIs like ConcurrentHashMap. Unfortunately, concurrent APIs require loops in order to handle conflicts and loops are not allowed.
Why is a solution to this problem needed? The solution would make it easier to write a BTrace script which detects concurrent access to an object.
The text was updated successfully, but these errors were encountered:
Easily worked around running BTrace in unsafe mode. The final solution would require a bit thought put to it but it might be addressed by an extension (when extensions to BTrace are available)
[reporter="nathan.reynolds", created="Thu, 7 Jul 2011 19:29:25 +0200"]
synchronized blocks are not allowed in BTrace. This makes it very difficult to write thread-safe code. For example, the following code snippet adds a key-value pair to a map if the key is not already in the map. BTraceUtils.newHashMap() returns a synchronized HashMap. However, there is no way to safely write the following code. Two threads can see that map.contains(key) returns false and both threads will call map.put(key, value) with two different values.
Map map = BTraceUtils.newHashMap();
if (!map.contains(key))
map.put(key, value);
else
value = map.get(key);
A synchronized block around contains(), put() and get() calls is needed.
A simple fix would be to provide concurrent data structures or APIs like ConcurrentHashMap. Unfortunately, concurrent APIs require loops in order to handle conflicts and loops are not allowed.
Why is a solution to this problem needed? The solution would make it easier to write a BTrace script which detects concurrent access to an object.
The text was updated successfully, but these errors were encountered: