Skip to content

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

@jbachorik

Description

@jbachorik

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions