November 29th, 2011

Things I've written that have amused other people, Episode 8

In a technical discussion, I opened a reply with

Bob’s paper which I haven’t yet read points out that…

Some people wrote to me to say that the’ve added this quote to their file in the hopes of being able to use it themselves someday.

For those who are curious, I found the technical discussion in question. It had to do with whether the following code is thread-safe:

// initial conditions
int x = 1, y = 0;
int *p = &x;
// Thread 1 executes this
y = 1;
MemoryBarrier();
p = &y;
// Thread 2 executes this
print *p;

Question: Can this code legitimately print 0?

Surprisingly, the answer is yes!

Author

Raymond has been involved in the evolution of Windows for more than 30 years. In 2003, he began a Web site known as The Old New Thing which has grown in popularity far beyond his wildest imagination, a development which still gives him the heebie-jeebies. The Web site spawned a book, coincidentally also titled The Old New Thing (Addison Wesley 2007). He occasionally appears on the Windows Dev Docs Twitter account to tell stories which convey no useful information.

0 comments

Discussion are closed.