AsyncLock 3.0 for .NET 5.0 Released

An updated version of AsyncLock has just been released on GitHub and Nuget with improved support for reentrancy detection.

AsyncLock is a async/await-native anonymous lock for .NET and .NET Core that allows safely using async/await while holding a lock, for example:

Continue reading

Compare streams quickly and efficiently in C# and .NET

Have you ever needed to compare the contents of two files (or other streams), and it mattered how quickly you got it done? To be frank, it doesn’t normally come up in the list of things you may need on a daily code-crunching basis, but that rather depends on what kind of programs you tend to write. In our world, let’s just say it’s not an uncommon task.

At a first blush, it would seem to be no harder than comparing two arrays. A pointer reading from each file, compare bytes as you come across them, and bail when things differ. And it would be that easy if you were to use memory-mapped files and let the OS map a file on disk to a range in memory, but that has some drawbacks that may not always be OK depending on what you’re trying to do with the files (or streams) in question. It also requires having a physical path on the filesystem that you can pass in to the kernel, and it unduly burdens the kernel with some not insignificant workloads that aren’t (in practice) subject to the same scheduling and fairness guarantees that user code would be, and they can tend to slow down older machines significantly1.

Continue reading


  1. Especially under Windows 

What happened to the sandy text editor?

The sandy text editor is an open source project from the team over at suckless.org, which make painfully minimal1 alternatives for popular tools and applications for unix-ish platforms.

But perhaps the tense being used here is wrong. For quite some time, sandy, suckless’ minimal vi(m) replacement, has been unavailable. The git repository is offline; the root cgit instance returning the following “No repositories found” message:

Continue reading


  1. Perhaps best described as borderline masochist in their austerity and spartanism 

pevents: a cross-platform Win32 events library

Threads-GitHubpevents, our implementation of Windows manual- and auto-reset events for Mac and Linux, is now officially pevents, our truly cross-platform win32 lightweight events library for Windows, Mac, Linux, and other platforms. We first released pevents way back in 2011, when we searched for and were unable to find an existing implementation of Windows events, the basic primitives for thread synchronization on Win32.

The *nix world has seen a lot of progress when it comes to non-blocking waits in recent years, but it’s very recently that purely event-driven libraries like epoll and kqueue have properly taken off. In the Windows world, it’s long-been possible to wait on filesystem and network events with WaitForMultipleObjects – a paradigm most Windows C/C++ developers are intimately familiar with. One thing that WaitForMultipleObjects (and pevents!) can also do rather neatly is wait on multiple mutexes, events, and/or semaphores simultaneously, unblocking when one or more (or all) are triggered or available.

Continue reading

Open Source, 100% Compatible ln for Windows (and Junction Point library)

We’ve been huge fans of symlinks for forever, and even posted about Windows Vista’s new mklink commandline utility with quite the passion back in 2006 when the ability to create soft-links from the commandline was first added to Windows.

However, there are a few things that have forever irked us about the ln lookalike called mklink.exe:

  • It’s called mklink and not ln. (I mean, you just get can’t get around that fact)
  • The arguments are switched around. `mklink something_doesnt_exist actual_file` is just…….. wrong!
  • By default, mklink will create softlinks and not hardlinks. ln requires the /h flag to create a hardlink.
  • mklink isn’t smart enough to distinguish between files and folders. You need explicitly tell it via the commandline.
  • Even then, mklink has two different switches depending on the type of directory link you want. /D for softlink’d directories, and /J for hardlink’d directories.
  • mklink can’t be used outside of cmd.exe (such as in PowerShell). (Hat tip: Jason)
  • And, of course,  mklink isn’t open source.

So we made our own.

Continue reading

Contributing to the Open Source Community

A week ago, we tweeted a promise to contribute more to the open source community. As a Research & Development organization, there’s a lot of random code samples, small libraries, forks/modifications of popular scripts, and more that’s just lying around, begging to be open sourced.

While a lot of these may prove to have little to no value to anyone, given how easy it is to make things open source thanks to github, there’s no real drawback to throwing them out there for anyone that may benefit at some unknown point in the future.

We have a couple of hundred miniature projects, test code samples, and other such content across a number of drives to sort through, and whenever we find something useful, this is our promise to the community to share it. To that end, we’ve set up a github repository at http://github.com/neosmart where we’ll be uploading the code, and from where you’re all more than welcome to check it out and contribute back.

Continue reading