Archive

Posts Tagged ‘threads’

Static vs. Dynamic Typing (Reflections on the Original Wiki)

March 24, 2010 5 comments

I’m not sure how I stumbled on the original Wiki at C2. It was probably (like a lot of people) an interest in the hype around “extreme programming” (remember that? “If it doesn’t work, you’re doing it wrong” – great times!)

I’m pretty sure all of my tiny flurry of activity on it was concentrated into a few months during 2000 (possibly a little in 2001), when it was already a sprawling activity-hive. So at least I wasn’t able to graffiti over it too painfully.
Read more…

Thread-Safe Mutable Objects using WSL (When, Silently and Loudly)

March 10, 2010 2 comments

What does this look like?

class ThreadSafeQueue<T> : ThreadStateful
{
    private readonly Queue<T> _queue = new Queue<T>();

    public void Enqueue(T item)
    {
        Loudly(() => _queue.Enqueue(item));
    }

    public T Dequeue()
    {
        return When(() => _queue.Count != 0)
               .Silently(() => _queue.Dequeue());
    }
}

Read more...

Categories: Uncategorized Tags: ,

Node#

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:

http://msdn.microsoft.com/en-us/library/bb648753.aspx

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

http://msdn.microsoft.com/en-us/library/microsoft.ccr.core.itask_members.aspx

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

Follow

Get every new post delivered to your Inbox.