December 24, 2006

You don't know jack about thread-safety

All you hotshot programmers need to drop what you're doing and secure a copy of Java Concurrency in Practice. 50 pages into the book my face was frozen in pure horror, as Brian Goetz and his friends happily ran over everything I ever thought I knew about thread-safe programming.

What do you think the following code will print to the console?

public class NoVisibility {

    private static boolean ready;
    private static int number;

    private static class ReaderThread extends Thread {
        public void run() {
            while (!ready) Thread.yield();
            System.out.println(number);
        }
    }

    public static void main(String[] args) {
        new ReaderThread().start();
        number = 42;
        ready = true;
    }
}

Unless your answer is "either zero, 42 or nothing at all" you really need to read the book before someone notices.

Comments (4)

December 08, 2006

There's nothing wrong with bloggers

<tom> there's nothing wrong with bloggers
<tom> it's just that like
<tom> when they're ALL in ONE ROOM, all SWEATING, all POSTING, 
<tom> all EDITING ONE DOCUMENT COLLABORATIVELY WITH SUBETHAEDIT, 
<tom> it gets a bit much
<liz> do non-bloggers not sweat then?
<tom> they do, but their sweat doesn't have an rss feed

Comments (0)