Some low level locking papers

It’s been a bit quiet around here, as I have been making my way through 50 or so videos of talks from //build/. I’ll do a summary post when I get through them all.

In the meantime, I’ve also been reading a few low level papers. It’s quite interesting that hardware transactional memory is becoming more available, and so this paper on malloc placement is worth a read – the transactional memory uses the cache lines in the L1 and L2 caches to see if a value has been modified by another party while the transaction has been happening. This means that caches can be affected by memory patterns that place many values into locations which map to the same cache line.

On the same blog there were also good posts on the liveness benefits of LIFO lock patterns and implementations of spin-then-park locks.

This gitbook on the Linux kernel is also worth reading if you are interested on how the system gets from a reboot to a running kernel, and this paper describes the many techniques for x86 virtualization.

Posted in Computers and Internet | Leave a comment

Effective Modern C++

Effective Modern C++ by Scott Meyers

C++ has changed a lot over the years and this book covers loads of the subtle points around the newer additions to the language. As usual with the Scott Meyer books, the author takes a number (42 in this case) of items grouped into 8 categories and discusses the issues around the particular topic.

The topics covered include perfect forwarding and so-called universal references, smart pointers which after C++ 14 cover most of the memory management scenarios, lambda expressions and the related issues around variable capture (and whether to capture the variables by reference or by value), and a very interesting section on concurrency in the new C++.

As in his other books, some of the sections are a little overwhelming in technical detail, but you always come away with a better understanding of a topic than when you started reading the issue. A good read and a good introduction to modern effective C++.

Posted in Books | Leave a comment

So how do you patch a deployed Nuget package

Quite some time ago, this blog post went past on the usual Microsoft RSS feed, discussing how Microsoft are going to make it possible to patch NuGet libraries. Using the standard mechanism of putting an assembly in the GAC and redirecting clients to use it via a publisher policy is a way to deploy a patch, but the article hints at an attribute that signals to Microsoft Update that such an updated assembly needs to be installed. I thought that it is was probably time to see what was happening.

Adding a NuGet reference to SignalR and then using Reflector to look at the assembly attributes, there is now a use of
[assembly: AssemblyMetadata(“Serviceable”, “True”)]
to flag the assembly to the runtime.

Looking in the CoreClr source code on github, in the assembly.cpp file there’s a GenerateBreadCrumbForServicing method which writes details about the assembly under c:\programData\Microsoft\NetFramework\BreadcrumbStore\ and sure enough when I look at that folder in explorer I see a mass of NuGet packages that my applications have loaded. These take the form of empty files with names such as

EntityFramework, Version=, Culture=neutral,PublicKeyToken=b77a5c561934e089

It will be interesting to see how well this mechanism works in practice – if I xcopy deploy something, there is going to be a delay between the first time I load the assembly (leading to the breadcrumb being set) and Microsoft Update running and fixing it up. I’m also interested in what other AssemblyMetadata attribute values there are being used, but investigating that is going to have to wait.

Posted in Uncategorized | Leave a comment

F# Deep Dives

F# Deep Dives by various

I was really looking forward to reading this book, and it was well worth waiting for. The book has many contributing authors, each of whom provides one of the 12 chapters. Of course, with such a diverse set of contributors, some of the chapters are more interesting than others, but many emphasise the benefits of F# as a functional first programming language.

There is an interesting opening chapter on how functional first programming languages can be effectively used in industry, but there were five chapters that I found particularly interesting. Parsing text-based languages looks at the task of writing a parser in F# and uses some interesting techniques such as active patterns to make it easy to read the resulting code. Chapter 6, integrating stock data into the F# language, offers a brief introduction to type providers, and then shows most of the steps to implementing type provider for CSV and YQL.

In the following section on developing complete systems, there are chapters on developing rich user interfaces using the MVC pattern which shows how F# can be used to write an application that uses WPF for its UI, a great chapter on asynchronous and agent-based programming that looks at ETL (extract, transform and load) models, and a chapter on writing games using XNA which emphasises the async workflow which can help keep the state machines of a game understandable.

You’ll learn something from all of the chapters and the book is well worth a read.

Posted in Uncategorized | Leave a comment

Time Reborn

Time Reborn: From the Crisis in Physics to the Future of the Universe by Lee Smolin

This was a very interesting read in the popular science category. It centres on the position on time in the laws of physics, first describing how time lost its place as a central focus of many theories, and then discusses the problems that this causes when physicists try to apply their theories to the universe as a whole. Smolin discusses how the reductionist approach of deriving laws by observing a system from the outside, is inapplicable to the discovery of the laws that govern the universe as a whole. The book is a mash up of interesting ideas from new theories and discussions around existing ideas and theories, all pitched at the popular science level with understandable explanations.

Posted in Uncategorized | Leave a comment

You can have your own CLR too

I was surprised when the source to the CoreCLR was published on GitHub a few weeks ago. Over the weekend I thought I’d start to build it and begin looking through the code in detail. I was amazed at how easy it is to build.

First you check out the sources from GitHub. Next you down the latest version of CMake and put it on your path. Then you run the build.cmd script. Your PC gets a bit busy for 30 minutes and then you have your own version of the CLR and the associated mscorlib.dll. [There is one gotcha concerning the DIA SDK that the script will warn you about – the fix is a copy from an older VS installation to the newest]

You can then use your existing C# compiler to compile against this version of the CLR.

c:\Windows\Microsoft.NET\Framework\v4.0.30319\csc.exe /nostdlib /r:D:\git\coreclr\binaries\Product\x64\debug\mscorlib.dll test.cs

and then run it using CoreRun

D:\git\coreclr\binaries\Product\x64\debug\CoreRun.exe test.exe

Brilliantly painless.

Posted in Computers and Internet | Leave a comment

JavaScript Ninja Secrets

Secrets of the JavaScript Ninja by John Resig and Bear Bibeault

This is a very good book which is so much more than a simple JavaScript language text. Sure, it covers some of the subtle points of the JavaScript language, and you are expected to have knowledge of JavaScript before reading the book, but it also offers a lot of information about some of the practical problems you will meet as a JavaScript programmer.

It starts in a slightly odd manner. There is a chapter discussing the benefits of cross browser development, followed by a chapter in which the  author writes a simple testing framework.  This framework allows you to embed tests inside an HTML page, and displays the results of the assertions inside the tests in an easy to read manner. Lots of the explanations that follow in the book will be expressed as assertions in the language of this testing framework. This way of working works very well.

The next section of the book, Apprentice Training, consisting of six chapters, has five chapters that focus on the subtle parts of the JavaScript language. The book focuses on the functional nature of JavaScript, discusses why it is important and then gives a very good explanation of scope and the four ways that you can invoke a function object – as a function, as a method, as a constructor and via apply and call. There is a good discussion of recursion followed by an example of memorisation, showing the big benefits of pure functional code. This is followed by a chapter on closures, which describes what they are and then shows how they can be used to implement partial application and temporary scopes with private local variables. We then go object-oriented in a discussion of prototypes and how they can be used to get features like those of standard OO languages. The author defines a JavaScript mini-framework that defines inheritance hierarchies that support a super operation to access base types. There is then a chapter on regular expressions, showing their great power (though you’ll need to be responsible to use them).

The last chapter of this section talks about the single threaded nature of browsers, the typical JavaScript host, and discusses how timers can be set and cleared. There is also lots of cross browser detail in how these things are implemented, and the book covers some of the common gotchas.

The next section, Ninja Training, first talks about runtime code evaluation, at first using eval and Function to make new function objects, but then moving on to describe the inbuilt decompilation (as you can ask a Function for its source code). There is then an interesting section showing some of the uses of these techniques.

The next chapter looks at with statements, a feature of JavaScript that you either love or hate. There is a small concise example that shows a powerful micro-templating engine that is written in a tiny amount of code, which shows the power of the features we have been shown before.

There are then two chapters on cross-browser strategies for using the DOM. Lots of practical discussion of the differences between browsers which taught me a lot about the DOM and how it should be used.

The last section, Master Training, also looks at browser differences, looking at the differences in the event model and CSS selectors.

The book is a really good read. It explains the parts of JavaScript that it covers really well, and you’ll learn loads about browsers and the DOM which is very interesting and useful if you do cross-browser work. The browsers that it discusses are a little behind the times, but that is probably the only complaint I have.

Posted in Books | Leave a comment