Archive for the ‘threads’ Category


December 15, 2009 2 comments

The node.js project is a rapidly evolving effort to build a runtime for writing event-driven servers in JavaScript. It’s part of a general JS renaissance, growing from a widening appreciation of the positive aspects of JS compared with other well-established languages such as C/C++ and Java. These include closures and dynamic typing, though I’d argue the former is much more important than the latter.
Read more…

Threadsafe Interfaces, Delegates vs Interfaces, Stuff Like That

October 26, 2009 3 comments

The mighty Skeet posted the other day about the idea of using a single instance of IEnumerable as a shared input for multiple threads (not that I realised at first, but I got there eventually).

Clearly the interface is no good for that purpose, because two operations (“check for existence of next item” and “read next item”) are exposed as separate methods/properties, so it can’t be made atomic. Jared Parsons has blogged a lot of times very readably about this.

This got me thinking, because I’ve noticed that I can often shrink an interface declaration down so it only has one method. And then it doesn’t need to be an interface; it can just be a delegate. That way you can implement it on the fly with a lambda expression. If you express it without any out/ref parameters, you don’t even have to declare a new delegate type. And if you have a Tuple class (as in .NET 4.0), you don’t need to declare any new types – just higher order methods.
Read more…

Categories: C#, functional, threads Tags: , ,

Referential Identity and Internship

June 30, 2009 Leave a comment

I was thinking about a gotcha in Java, and started wondering about the idea of making it convenient to intern reference objects.
Read more…

Categories: .NET, C#, Interop, threads Tags: , , ,

Readonly Fields and Thread Safety

March 6, 2009 1 comment

In C# you can mark the fields of a type as readonly (indeed you generally should if it’s a struct). By doing so, you make it illegal to change the fields except in a constructor of the type.

The advantage of this is that readonly data can be shared freely between threads without any thread causing updates that may be seen "in progress" by other threads, simply because there never will be any updates.

But is this strictly speaking true? Nope.

Read more…

Categories: immutable, threads Tags: ,

Other Examples of Iterators and Async IO

December 9, 2008 2 comments

The idea of returning functions via yield return to simply asynchronous IO programming has a precedent in Microsoft’s Concurrency and Coordination Runtime:

Although they are yielding interfaces, really they are yielding functions:

The ITask interface has only one really important method: Execute, which means that really it’s a function (a delegate in C# terms). I think the functional style makes the whole thing cleaner, but the point is that the idea was already in use in the Microsoft’s CCR, perhaps as long ago as 2005 (although that’s difficult to verify).