Comparison: ChainLocker vs. Heirarchical Mutexes

Posted in programming on March 8th, 2013 by Samuel Kenyon

In “Concurrent Programming with Chain Locking,” Gigi Sayfan presents a C# class demonstrating chain locked operations on a hierarchical data structure. This reminded me of lock hierarchies described by Anthony Williams in the book C++ Concurrency in Action.

To take a step back for a moment, the overall goal is to create multithreaded code which doesn’t cause deadlocks, race conditions, etc.  Although it may seem like a confusion of metaphors, lock hierarchies are a type of hand-over-hand locking, which is basically defined lock ordering. I think it would be fair to call a “chain” a particular path of locking through a hierarchy. Defining lock ordering is what you do if you can’t do the better idea, which is to acquire two of more locks in a single operation, for instance with the C++11 std::lock() function.

As Herb Sutter pointed out in his article “Use Lock Hierarchies to Avoid Deadlock,” you may already have layers in your application (or at least the data in a certain context). This can be taken advantage of when making the software concurrency-friendly. The general idea is that a layer does not access code in layers above it. For mutexes, this means that a layer cannot lock a mutex if it already holds a mutex from a lower layer.

Read more »

Tags: , , ,

A PIC-Based Scripted Robot System

Posted in making and hacking, robotics on January 7th, 2013 by Samuel Kenyon

The last time I used the aforementioned scripting framework was in the robot system described here. It was intended for a spherical robot, however, I also used an old RC truck chassis for testing. It was fairly generic—there wasn’t anything specific to spherical robots in the board design or programming, with the exception of the size and shape of the board which was made to fit in the sphere shell.

The Board

My embedded robot control board.

My embedded robot control board.

This robot used an 8-bit microcontroller (uC) based board that I hacked together. All of the robot code, including comms, the script engine, sensor interaction, and motor control ran on the uC. There was no in circuit debugging / programming; I used a separate device programmer (specifically, the EPIC Plus Pocket PIC Programmer with the 40/28 pin ZIF adapter). The uC I used was a Microchip PIC18LF458.

Read more »

Tags: , , ,

Robot Scripting

Posted in programming, robotics on January 2nd, 2013 by Samuel Kenyon

During 2003 and 2004, I worked on FIRST robots. I was a college student, but Northeastern University hosted a team supporting multiple high schools. FIRST competition robots are radio controlled, however autonomous routines activated by the operator are allowed and would be hugely advantageous. But most teams never got to that point, and were lucky to have much beyond the default code.

I also started making my own robots. I had hacked at robots before, but I hadn’t made my own that actually worked until 2003. First I used parts from the IFI Edukit that came with one of the FIRST robotics kits to make some little experimental robots and one that was intended for a Micromouse competition (but wasn’t finished in time). Eventually I made my own microcontroller based board which I attached to an RC truck chassis.

my robot truck

In all of these cases, I started to realize that a lot of basic things that we wanted these robots to do could be represented with simple scripts.

Read more »

Tags: , ,

The Code Experience vs. the Math Experience

Posted in culture, philosophy on November 29th, 2012 by Samuel Kenyon

In the book The Mathematical Experience, the chapter on symbols mentions computer programming [1]. But it really doesn’t do justice to programming (aka coding). In fact it’s actually one of the lamer parts of an otherwise thought-provoking book. It’s not that it’s dated—a concern since the book was published in 1981—but that the authors only provide the paltry sentence, “Computer science embraces several varieties of mathematical disciplines but has its own symbols,” followed by some random examples of BASIC keywords and some operators.

cover of the edition I have

As mentioned in “The Disillusionment of Math,” I’ve always thought of programming as different than mathematics. And I almost always choose the experience of thinking in code over the experience of thinking in equations.

But I suspect others think of these as similar activities occupied by mathematical people. Likewise, if a programmer tells somebody that they are a software engineer, the keyword “engineer” can create a response of “oh you must do a lot of math.”

Read more »

Tags: , , ,