It starts out sounding ridiculous. Stick with it to the punchline.
I think you assumed my example with futures implied parallelism, but it doesn't. You could use an ExecutionContext that would execute everything in the main thread, but you typically wouldn't.
My point was just that the asynchronous code was going to be uglier than h(f(x), g(x)).
That said, I think the only reason you'd want to write asynchronous code is for parallelism. Even with a single thread, you can still benefit from I/O parallelism. (Which is presumably why people are writing async code in JS.)
Tonight I finished ("finished") a computer keyboard project. Built two ErgoDox kits from (one for home and one for work), and replaced the switches in a pair of Genovation CP24 keypads to go with them.
(I want more keys readily accessible than the ErgoDox provides on its own - unlike many folks, I actually use my function keys. But the nice thing about the ErgoDox is that it's completely open-source, so the firmware is fully programmable.)
I'm still refining the key layout, but at the moment it is roughly per:
In a continuing experiment, I also replaced the USB controller chip in a Delcom foot pedal for modifier keys (Alt, Shift, Ctrl, and Tab) with a Teensy microcontroller.
The way the Delcom chip encodes modifiers is buggy in a way that interacts badly with the Linux keyboard driver, and it was easier to replace the chip than to either get Delcom to fix the firmware or get the Linux kernel patched to avoid Stupid Things.
In retrospect, it would have been a lot cheaper to buy the pedals and microcontroller separately and DIY from the start, but I wasn't expecting buggy firmware.
I should have known better - if there's one thing you can rely on, it's that software is broken.
A while back, my brother-in-law saw a thing going around where someone had replaced the guts of a broken NES with a Raspberry Pi running an emulator. In addition to allowing the games to be played at all, it has an HDMI output that makes it compatible with modern televisions (unlike the NES's somewhat nonstandard half-resolution composite output).
From that point, I knew what he and my sister were getting for Christmas. =)
Now, the version he saw was a nice proof of concept, but it has some hacks. It doesn't use the original connectors at all - just the power switch. But the Pi has some lovely General Purpose Input/Output pins, the NES controller protocol is fairly well-understood, and the original power supply even runs at a convenient 5 volts.
And as it turns out, there are some People on the Internet who are very serious about emulation on the Raspberry Pi and have written nice setup scripts for connecting controllers and arranging emulators.
So step one was to acquire a non-working NES on eBay. I took out the guts, but desoldered the original RF/power module in order to provide +5V for the Pi. For a brief period, I also had the RF modulator working with the Pi's composite output - Linux on channel 3! Unfortunately, I burned out the RF amp when I accidentally left the power connected during hookup. =(
Fortunately, the +5V supply still worked fine, so I bypassed the original modulator and wired the analog audio and video to the original red and yellow ports. (They don't work without some software tweaks, but we'll get to that later.)
Next step was to figure out where to place the Pi. I got some HDMI, Ethernet, and USB extensions (from Adafruit Industries), and it turns out that an XBee breakout board (from ) has the right spacing for the original sockets for the controllers. (Those connector sockets were a huge pain to desolder, but they make it possible to replace the front panel connectors if they wear out without re-soldering any connections.) The original expansion port is pretty narrow, so there wasn't a lot of room for so many components - I ended up shaving the rubber connectors off of the HDMI and Ethernet cables with a knife to be able to fit them closer together.
I cut out sockets for the new connectors with a Dremel and an X-Acto knife, starting with the expansion port to get used to working the material before the more cosmetically-visible HDMI port. The cuts are a bit rougher than I might prefer, but all in all I'm pretty satisfied with how they turned out.
After that, it's just a matter of wiring. I used headers soldered to a small proto-board to keep things modular for testing and rebuilding (and to provide a spot to add a resistor for the front-panel power LED). The controllers share common pins for clock and latch and each have a dedicated pin for data output. They're wired off the +3.3V rail provided by a voltage regulator built into the Pi.
So, actually, I lied. It's not a simple matter of wiring - the controller driver requires an updated kernel and firmware blob for the Pi, and the Raspbian OS doesn't use the same mechanism for kernel upgrades as standard Debian. Once I finally figured out that aptitude wasn't actually upgrading the kernel, things went a lot more smoothly.
There was one minor hitch remaining: only one of the controller sockets worked! After a bit of debugging, I discovered that one of the GPIO pins wasn't happy about the signal it was getting from the controller. (The controller is designed to work with a +5V source, so running it at +3.3V apparently makes it a bit noisy.) Fortunately, switching to a different pin (and tweaking the driver accordingly) made everything finally work.
It was striking to me just how much of the work was "figuring out how to fix things" rather than "actually fixing things" - lots of time tweaking resistors (before the RF burnout, at least), fighting with Raspbian's idiosyncracies, and trying to stuff a Raspberry Pi and three connectors into one little expansion port.
Anyway, it was a fun little project and I hope they enjoy the new old toy!
One of my hobby programming projects (a programming-language experiment in the very early stages) is in C++11. At my day job, I've used the googletest framework fairly widely, and it's honestly pretty good. But I'm trying to keep my dependencies as close as possible to just the C++11 standard library, perhaps with some POSIX APIs for interactive tools.
I've also been writing a lot of Go lately - and the Go approach to testing is very bare-bones. As I've heard Rob Pike put it: "Test code is just code."
One of the things that I've noticed in working with Go is that tests tend to fall into two categories: functional and stateful.
For functional tests, I generally want the test structure to be:
1) Generate some input.
2) Call a function with the input.
3) Compare the function's output to the expected output.
4) If the comparison fails, log the input, the name of the function, and the difference between the expected and actual output.
For stateful tests, I generally want the structure to be:
1) Do some setup.
2) Call a function.
3) Compare the state after the call to the expected state.
4) If the comparison fails, log all of the relevant setup steps, the name of the function, and the difference between the expected and actual end state.
As it turns out, it's easy to express a functional test in terms of a stateful one, but not the other way around. "Do some setup" becomes "generate the input", and "the state after the call" becomes "the result returned by the call".
So now I have a clear API target: if I can make stateful tests reasonable, I can probably handle functional tests as well.
So what's next? One of my major goals in writing tests is to notice and fix and awkward usage in my API. So my test program needs to resemble a real C++ program using my API. Test setup should be C++ statements executed in ordinary program order; conditions should be C++ booleans; the test program itself should have a main() function and ordinary scoping.
I ended up writing a minimal testing package in ~135 lines of C++ and C Preprocessor. It's by no means perfect, but it's about as readable as a googletest test and the output is much more useful - if a test fails, I can figure out all of the relevant events without even needing to open the test file.
(The new machine is much higher-power than my other Linux box, so I want to have something resembling decent power-management. We'll see whether Linux is up to the task.)
At any rate: the default behavior of the Linux kernel is to overcommit arbitrarily, and with some sysctl tweaks you can get that down to "only commit memory equal to swap + a configurable fraction of RAM".
Now, the kernel won't even boot if the RAM fraction is too low - the init sequence applies sysctl.conf before it enables swap, and that means it will refuse to start all the other system-critical services that need RAM. So, in practice, you have to allow at least a little overcommit compared to your swap space. And if you try to shut down with overcommit off, the system hangs - it apparently still needs to allocate memory after it disables swap.
But the default Linux hibernation mechanisms - uswsusp and tuxonice - both reuse the swap space for hibernation!
So what happens if you try to hibernate while the system is already at peak utitlization? I don't know, but I'm guessing the OOM killer goes rampant again.
So, how can we make hibernation play nicely without overcommit?
One thought I had was to add something to the init sequence to disable overcommit at the end of boot and re-enable it again before shutdown. Seems unpleasant, but perhaps workable.
Any other ideas?
> You could probably add support for dedicated hibernate partitions. It might be easier to add a new overcommit_policy.
Yeah, in this case I'm not motivated enough to hack on the kernel myself. If my goal is "reliable software", I'm sure the Linux kernel can acquire sources of unreliability far faster than I can mitigate them.
> I do wonder what it is you're doing where performance is irrelevant but hibernate must be guaranteed to work without supervision, except in the case of hardware faults.
No, you misunderstand. My objective is (as close as possible to) a system in which everything either works or fails gracefully except in the case of hardware failure. "hibernate" is a special case of "everything".
Performance is absolutely relevant, but in the wasteland of Linux there is no obvious way to get hibernate support without swap. And I occasionally need to run Java programs; the JVM assumes that it is running with overcommit and can pre-allocate arbitrarily large amounts of memory without even intending to use it.
> Oh, have you considered ulimit/setrlimit, or do you need arbitrary code to be able to run as root with all capabilities enabled?
setrlimit doesn't have a working option to limit actual memory usage - support for RLIMIT_RSS was removed in 2.4.30. (See what I mean about not wanting to hack on the kernel myself?)
cgroups are closer to what I want, but too much configuration overhead.
The Lost Kerbonaut
One of my Kerbonaunts in #KerbalSpaceProgram accidentally got stranded on Eve without enough fuel to return home. After a couple decades of dedicated Kerbin R&D - and several rescue vessels - he has finally been returned to Kerbin intact with his precious payload of Eve experiments and surface samples!
- listening and playing
- anything from experimental/microtonal to alt-country
- voting systems
- political philosophy
- scuba diving
- board games
- programming language design and systems programming
- (and the unfortunate lack of intersection of the two)
- Sandwich Science (and general culinary experimentation in the home)
- and science news, particularly physics and biology
(Late Show) The Ragbirds with Eric Oliver and the Brain Festival and The...
Pittsburgh's Premiere 'Wired' Music Nightclub
Developer Guides and Manuals | AMD Developer Central
Title, Format, Date. New AMD Opteron(TM) 6200 Series processors "Linux Tuning Guide", PDF, 04/23/2012. BIOS and Kernel Developer G
Joe Pug with Special Guest David Wax Museum | Events | Club Cafe
Pittsburgh's Premiere 'Wired' Music Nightclub
Vibram FiveFingers : Barefoot Sports Shoes : Toe Shoes & Minimalist ...
The human foot is comprised of numerous bones, joints, sensory receptors, tendons and ligaments. To keep feet stimulated, we recommend weari
(Early Show) Enter the Haggis with Special Guest The Weathered Road | Ev...
Pittsburgh's Premiere 'Wired' Music Nightclub