- A Concurrent Affair - https://www.concurrentaffair.org -

Lots of Writing

The last week and a half, I’ve mainly spent writing. I’m working on my MS thesis, and of course, I’m running behind. I’m not sure if I can complete everything on time, but I’ve signed up for graduation this semester. Regardless of whether I’ll make it or not, that’s a good thing (except for my pocketbook; if I don’t graduate, I’ll pay a fine), because if I hadn’t signed up, I probably wouldn’t be writing right now with this much ferocity. I’m consciously trying to stay away from getting involved in other activities.

Right now, I’m averaging about four pages a day, but I don’t care too much about the wording and I frequently write something while realizing that it’s in the wrong spot. I’ve rearranged my thesis several times already. I also just added a chapter. That was a result of printing out this very blog and starting to go through it for important information. I knew keeping this blog would pay off. The blog printed as 270 pages. I kind of feel like that’s MS-worthy already, but of course the style of writing is much too informal.

Anyway, I’m still going through the blog, marking important passages. Right now, it’s a strictly analog process with a highlighter and a red ink pen, but I’m thinking about how I can digitize the effort. Maybe I’ll add comments.

I’ve been in touch with the JUnit people and have created a completely separate plugin [1] for JUnit 4.x that performs exactly what my modified JUnit does, except that it needs to be optionally invoked using Junit 4.x’s @RunWith [2] annotation. I don’t think this is philosophically the right thing to do, but practically it probably is: Otherwise, thousands of existing unit tests would break.

I also realized that there’s one very important part of a threading discipline for which I don’t provide any suitable predicate: Checking whether an object’s lock (monitor) is actually held. That’s probably one of the most common requirements, right after specifying a certain thread. I added code to do just that, and I abused a side-effect of Object.wait [3] for that: If the object’s lock isn’t held, an IllegalMonitorStateException is thrown. If it is thrown, then I know the lock isn’t held. So I basically do the following:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/**
 * Return true if the current thread owns the monitor of the object.
 * If this method is directly used in a predicate annotation, then the object
 * passed is "this".
 * @param o object whose monitor should be checked; must be non-null
 * @return true if the current thread owns the monitor (false if o is null)
 */

public static boolean checkMonitorOwned(Object [4] o) {
    if (o==null) return false;
    boolean interrupted = true;
    while(interrupted) {
        try {
            o.wait(10);
            interrupted = false;
        }
        catch(InterruptedException [5] e) { /* ignore */ }
        catch(IllegalMonitorStateException [6] e) { return false; }
    }
    return true;
}

I’m aware that this can quite severely change threading behavior because of the wait and the timeout of 10 milliseconds, but it should be quite clear by now that full-fledged predicate annotations can be quite dangerous. Anyway, this is a very important addition. The predicate annotations that go along with it (and that are available for download [7] and immediate use now) are OnlySynchronizedThis (which requires the code to be synchronized on this), OnlySynchronizedField (which specifies an object by class and field name whose monitor must be held) and OnlySynchronizedField.ByName (which does the same, but specifies the class by name), and their complements NotSynchronizedThis, NotSynchronizedField and NotSynchronizedField.ByName, which all do exactly the opposite, respectively.

Oh, and I’ve also moved the small Perforce server with just one user, which I’m using as a backup and “time machine”, from the Windows 2003 Server that Dr. Wong has let me use for such a long time to the Linux box that Corky got me. I always wanted to move it to Linux because of the improved scripting capabilities, but I haven’t been able to get those to work yet. So while it may seem like I haven’t done very much recently, and I clearly haven’t written very much, that’s not true.

PS: I have the unfortunate obligation to say goodbye to another Rice friend, Andrew Ladd. He passed away after a long struggle with cancer. I greatly admire him. I can only say that, while he died, he has definitely won his struggle. Goodbye, Andrew. You’ll be missed, too.

[8] [9]Share [10]