Skip to content
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

[BTRACE-74] Make it easier to write a BTrace script which detects concurrent access to an object. #77

Closed
jbachorik opened this issue Aug 28, 2014 · 2 comments

Comments

@jbachorik
Copy link
Collaborator

[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.

@jbachorik
Copy link
Collaborator Author

[author="j.bachorik", created="Wed, 13 Jul 2011 20:39:43 +0200"]

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)

@github-actions
Copy link

Stale issue message

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant