A Code Workaround for a Busted Furnace
warmup.cpp: [code]
Late last December, I woke up and it was freezing in my apartment. I checked the thermostat, and it was already less than 60 degrees! I turned it from hot to cold to hot. And again. I turned it all the way up. The furnace never clicked on. COME ON! I checked, and the pilot light was on, so I had no choice but to call maintenance to get it fixed.
Most days this wouldn’t have been a problem, since it would be fixed while I was at work, but I was in my end-of-year vacation-burning crunch. Maintenance always fix minor problems really fast, so I knew it would take all day to come and fix the heater. Sure enough, help didn’t arrive until 6PM.
I tried lying motionless on the floor under some blankets and played some Assassin’s Creed 2. This worked for an hour or so, but if I’m at home all day and not working on something on the computer, I start to feel like a waste. This was in the middle of trying to get a side project of mine off the ground, and I wanted to get a beta version working before returning to work in January.
Could I use my laptop as a heater? It gets pretty warm when the CPU runs at full blast on one core. If I kept both going for hours, would that be enough?
8 minutes later, I had a C++ program that ran 2 CPUs at full blast. I hate picking C++ for a personal project, but I’ve used it for 10 years and I’m just not familiar enough with any other language’s CPU usage patterns to do the work that quickly. I probably didn’t have to worry, but I was cold!
The program, warmup, runs NUM_CPU copies of this thread:
int fn(bool *go) { double a = 0; static mt19937 rng(static_cast<unsigned> (std::time(0))); normal_distribution<double> norm_dist(1.0, 1.0); variate_generator<mt19937&, normal_distribution<double> > normal_sampler(rng, norm_dist); while(*go){ double val = normal_sampler(); a += val; } return 0; }
I already had Boost, and I’d never used their pRNGs before, so I decided if it was a copy/paste job, I would give them a test run. Sure enough, it plugged right in.
The main function is even simpler:
int main() { bool go = true; boost::scoped_ptr<boost::thread> threads[NUM_THREADS]; for(int i=0; i<NUM_THREADS; ++i) threads[i].reset(new boost::thread(fn, &go)); std::string asdf; cout<<"enter any input and hit <Enter> to kill"<<endl; cin>>asdf; go = false; for(int i=0; i<NUM_THREADS; ++i) threads[i]->join(); return 0; }
Within 12 minutes of starting, I was nice and toasty!
I posted the code on Github in case I needed it somewhere else: [code]
Popularity: 1% [?]

Reader Comments
I don’t really know what else to say other than way to take the initiative. I suppose success will come easy to those who use personal ingenuity to create their own heat.
Lol, I keep my house at 60deg most of the time. If you’re in the area you should pop by. Hope all is well!
When I lived by myself, I kept it pretty cold (~64 or so), but this was absolutely ridiculous. I’m busy the next weekend or two, but I’ll definitely take you up on that!