Tuesday, June 26, 2012

Healthy Living

As my better half, KLa is in charge of making sure I don't die before she does and leave her saddled with a bunch of medical bills related to my debaucherous, pre-marriage cuisinic lifestyle of frozen pizzas, ramen noodles, and peanut-butter crackers (hey, peanuts are practically vegetables!).

As a result, she makes us healthy meals full of fruits, vegetables, and grains who would turn up their noses at the thought of processing, sneer at artificial flavors, and turn green at the sight of red dye #40.

Ever in pursuit of the pinnacle of haleness, however, she went hunting for a healthier alternative to our usual breakfast oatmeal.  I suspect that as a common ingredient in cookies it's guilty by association, but KLa refuses to confirm or deny this.

Anyway, a couple mornings ago she presented me with a bowl of quinoa, which I believe is Spanish for "a bowl of oddly-texured brown and yellow seeds that look like frog-eyes."  According to the wiki page it's related to "pitseed goosefoot," which I think says it all.  It's how I always imagined eating plankton would feel like, and yes, as a fan of Kon-Tiki I've imagined what eating plankton would be like.


Monday, June 04, 2012

Debugging mutex locks in threaded programs using GDB

A common problem I have while debugging a threaded program is trying to determine which thread currently has a mutex lock when another thread is stuck waiting at the lock.  This could be because the two threads are deadlocked, or perhaps the first thread simply forgot to unlock the mutex.

Piecing together information from StackOverflow and my own experience, here's a possible way to go about it:

1. Run your program using GDB

$ gdb program
(gdb) run

2. When the program freezes, stop it using Ctrl-C

^C
Program received signal SIGINT, Interrupt.
0x0012d422 in __kernel_vsyscall ()

3. Do a backtrace to see where we're deadlocked.

(gdb) backtrace

#0  0x0012d422 in __kernel_vsyscall ()
#1  0x0013aaf9 in __lll_lock_wait () at ../nptl/sysdeps/unix/sysv/linux/i386/i686/../i486/lowlevellock.S:142
#2  0x0013613b in _L_lock_748 () from /lib/tls/i686/cmov/libpthread.so.0
#3  0x00135f61 in __pthread_mutex_lock (mutex=0xb2601660) at pthread_mutex_lock.c:61
#4  0x08167cc9 in ObjectManager::lockObject (this=0x8280998, ObjectId=2992640368) at program/src/ObjectManager.cpp:1212
#5  0x08164929 in ObjectManager::executeActions (this=0x8280998, actions=...) at program/src/ObjectManager.cpp:424
#6  0x08174d09 in main (argc=1, argv=0xbffff6b4) at program/src/main.cpp:110

From this, we can see that we're stuck at line 1212 in ObjectManager.cpp (frame 4).  (Look for the frame right before the frame containing __pthread_mutex_lock)

4. Switch to the frame.

(gdb) frame 4
#4  0x08167cc9 in ObjectManager::lockObject (this=0x8280998, ObjectId=2992640368) at program/src/ObjectManager.cpp:1212
1212            pthread_mutex_lock(&mutex);

5. Determine which thread currently holds the lock we're attempting to obtain.

Look for the mutex.__data.__owner value.  This is a thread ID, or in GDB parlance, a light-weight process (LWP) ID.

(gdb) print mutex
$2 = {__data = {__lock = 2, __count = 0, __owner = 19617, __kind = 0, __nusers = 1, {__spins = 0, __list = {__next = 0x0}}}, __size = "\002\000\000\000\000\000\000\000\241L\000\000\000\000\000\000\001\000\000\000\000\000\000",
  __align = 2}

(gdb) info threads
  9 Thread 0xb47d0b70 (LWP 19619)  0x0012d422 in __kernel_vsyscall ()
  8 Thread 0xb4fd1b70 (LWP 19618)  0x0012d422 in __kernel_vsyscall ()
  7 Thread 0xb57d2b70 (LWP 19617)  0x0012d422 in __kernel_vsyscall ()
  6 Thread 0xb5fd3b70 (LWP 19616)  0x0012d422 in __kernel_vsyscall ()
  5 Thread 0xb67d4b70 (LWP 19615)  0x0012d422 in __kernel_vsyscall ()
  4 Thread 0xb6fd5b70 (LWP 19614)  0x0012d422 in __kernel_vsyscall ()
  3 Thread 0xb77d6b70 (LWP 19613)  0x0012d422 in __kernel_vsyscall ()
  2 Thread 0xb7fd7b70 (LWP 19610)  0x0012d422 in __kernel_vsyscall ()
* 1 Thread 0xb7fd8800 (LWP 19607)  0x0012d422 in __kernel_vsyscall ()

6. Switch to the owning thread.

(gdb) thread 7
[Switching to thread 7 (Thread 0xb57d2b70 (LWP 19617))]#0  0x0012d422 in __kernel_vsyscall ()

At this point, you could run a backtrace on the owning thread to see what it's doing and perhaps get clues as to why it never unlocked the mutex our original thread is still gamely waiting for.

Saturday, June 02, 2012

Bees

Just a quick picture of our bees!


Monday, May 28, 2012

Fence II: The Return of the Fence's Revenge

Despite naturally missing my wife and daughter terribly, with them on vacation, today was a great day for getting things done.  I tackled the fence on the right side of the house and even without missionaries from church to dig the postholes it was fairly easy going.

Unlike the left side of the house with its five sections, steep hill, nearby tree, and double-wide gate, this piece was only two eight-foot sections on flat ground.  The most complicated part was figuring out how to join it with the Leaning Tower of Cheap Engineering that was the remains of the previous fence.

Fortunately, it was tilting enough that the termites apparently had a hard time keeping their footing and had left enough wood that it was still somewhat translucent.  I decided to salvage what I could, but some of it was bad enough that it had to go.  As I dug up one of the posts that I was going to replace, I was amazed by how little concrete the builders had originally used.  No wonder it was leaning!  I've seen more concrete stuck in the treads of my tires.

The finished product was decent (guess which half is the new half):



When our company had moved into its new building, the landlord was going to throw away some old chain-link fence material, so I had borrowed the U-Haul our company was using and took it home instead.  This is what I still have left after doing the fence today:


While an elephant-proof fence is a laudable goal, an eight-foot tall gate has a certain imposing feel that could be a little off-putting to neighbors and visiting relatives, and perhaps lead to passing policemen wondering if we were growing marijuana in our backyard.  Then again, maybe they wouldn't care.  Anyway, I bought a metal-cutting blade, took my handy Sawz-All, and trimmed two feet off the gate:


When mounted, it looked a little...headless, but that didn't affect operations.  At least we don't have to worry about Ash being carted off by coyotes now!  Or at least once I mount a latch of some kind. 


All in all, a good day's project.  Next up, the 130 feet of fence at the back of our property!  And by next, I mean of course next year.




Friday, May 25, 2012

Free Time

An apparent side-effect of KLa and Ash being on vacation is that I have lots of time to blog.

Future Politicians, Today

I can't be the only one wondering how the politicians of tomorrow are going to spin the Facebook posts and Twitter tweets that they're generating today. 

During any given election season, political mudslingers dig up old college newsletters or newspaper articles where their opponents may have said something potentially spin-worthy.  Their resources are limited, however, and rarely extend past the point that their opponent became a public figure and therefore news-worthy.

Nowadays, however, anywhere between 25% and 50% of Americans have Facebook accounts, and that probably skews young.  There will be no shortage of embarrassing photos, awkward tweets, and ill-advised posts made in a brief moment of insanity (the so-called "teenage years").

The more I thought about it, though, the more I started to lean towards "it won't matter."  Politicians are naturally shameless to begin with and besides, these social media accounts are so ubiquitous that their opponents will probably have one too, leading to a MAD scenario.

Regardless, it will be interesting to see how it plays out.  With Myspace and Facebook hitting nine and eight years old, respectively, the standard teenage early-adopter will be halfway through their law degree by now.  Give them another decade and we'll start to see the fireworks.

Vacation Pros and Cons

Pros and cos of KLa and Ash being on vacation:

Pros:
  • I vacuumed an entire floor without the vacuum being unplugged even once.
  • I got to sleep in until 6:45 am
  • I took an entire shower without having to lean out dripping wet to lift someone onto the potty.
Cons:
  • I didn't get to chase a squealing and laughing two-year-old around with the vacuum.
  • I woke up alone in bed, without a wife to drape an arm over or a two-year-old climbing in saying, "Food time?"
  • I had a cheese sandwich for breakfast instead of an omelette or banana-raisin waffles.
Not sure if I'll survive two weeks.

Vacuuming Revelation

The past couple days KLa has been waking up with a handful of bug bites.  Worried that the mice we recently fought may have brought fleas into the house, she sprinkled Borax all over the floor before she left for Utah and drafted me to vacuum it up later that night.

As I was vacuuming it up, the thought occurred to me that it might not matter what powder you sprinkled on the floor.  It could be glitter and be just as effective--what it did was show me how terrible of a vacuumer I normally was.  It took me three or four slow passes to get up all the Borax and since my usual technique is one or two quick swipes, it's not hard to do the math and realize that maybe my standard vacuuming is fairly ineffective.

In short, regardless of whether the Borax actually did anything to the potential fleas, at the least it made me vacuum properly.

Counter-Culture

I've always pictured myself as a rebel--a counter-culture anti-establishment kinda guy who ignores the usual societal norms and boundaries and laughs in the face of tradition.  Take this morning for example--I had a cheese sandwich FOR BREAKFAST.

Stupid moths, getting in my cold cereal...

Thursday, May 24, 2012

Open Source and Productivity

I was so productive this evening that I decided to finish it off with a little blogging.

I love my job.  There isn't a day that I don't look forward to going into work.  With KLa and Ash leaving for Utah this morning, I was left with a free evening and the activity that sounded the most fun was to go back to work after dinner. 

If there was one downside to my job, however, it's that everything is "Proprietary and Confidential."  We use a lot of open source software (OSS) at work, but it's pretty one-directional--we only select OSS software that doesn't require us to contribute back.  It's a fact of life for a proprietary company like ours, but still not the dream world I would live in if I could. Every since I could program I've worked on and contributed to open source projects and I've always enjoyed the open sharing.

For the past couple days I've been working on adding joystick support to our software.  It's been a fun project, made infinitely easier by finding two pieces of OSS that make working with joysticks a breeze.  I did run into one snag, though--one of the joysticks just wouldn't work properly.  After spending some time on my own troubleshooting, I looked up the chatroom where the developers hung out and grilled them with some questions.
With their guidance, it took 20 minutes to fix the bug instead of two hours.  I went away with a fix for my problem and a big savings in time, and they went away with an improvement for their software.  That's what my perfect world would be like all the time--everyone sharing, and everyone winning.

Until then, I'll keep enjoying my job, and mentally thanking all those open source developers who put so much of their time and resources into making free and incredibly useful software, asking little and requiring nothing in return.

Wednesday, April 25, 2012

Andrenaline Junkies Got Problems

Ah, nothing quite like the glare of oncoming headlights in your lane to get the adrenaline flowing!  The thrill of adventure, the squealing brakes, the wife tourniqueting the arm...just another day in California driving.

Thursday, April 19, 2012

Fence

Thanks to my father and his darn do-it-yourself ethic, KLa and I decided to take a stab at putting up a new section of fence ourselves.

We probably wouldn't have done it ourselves except interestingly, it was like pulling teeth to get a quote on our fence.  We had a general contractor acquaintance come over and measure, but he never followed up.  I know for a fact he was looking for work, which is why I offered the job to him, but I suspect he weighed digging postholes in California's rock-hard soil and eating, and decided ramen wasn't that bad.

Our neighbor wanted to repair a joint section of our fence (the section from our side that was in the best shape and the last one we would have done if it was up to us, unfortunately) and had a man come out to give a quote.  He, too, made measurements, then vanished and never reappeared.  It's odd.

So we decided to take a shot at it ourselves.  My dad and I had put up a fence when I was younger so between that and a few websites (and a healthy dose of "winging it") we got what we needed and began.

First, Ash waterproofed the boards:



The missionaries from church were eager for a service project and I was happy to oblige.  For the cost of a couple burgers from Five Guys, they did all the heavy work of digging the postholes.  (Note to self: don't put a posthole so close to a tree next time. Whoever you sucker into digging the hole will take a long time getting through the roots.)  I poured cement, cut boards, and "managed."


KLa and I put up the first section of slats, and later the missionaries came over and again and helped finish it off.


My bro-in-law came over and helped build the gate.  And just like that we were done!


Granted, the project was spread over about a month and a half of Saturdays, leading our back-fence neighbor to jokingly question which dynasty we were planning to finish the Great Wall in, but the end result wasn't half-bad.  You can tell just by looking at the fence that some good management went into it.

Our next project is the fence on the other side of the house, and I hear a new missionary moved into the area.  I wonder if he's ever dug postholes...

Monday, April 02, 2012

Bedtimes

Friday night and Saturday night, Ash got to bed super late--9 pm or later.  The next mornings, she woke up super early--4 or 5 am. 

Last night we finally got Ash to bed at a reasonable hour--7:30 pm or so, and she happily slept in until 7 am. 

Moral of the story: get Ash to bed on time.  (And it doesn't hurt if I get to bed on time, too...)

Tuesday, March 20, 2012

Robotics update

5D Robotics recently posted some videos we shot about the current state of our robots (I especially like this one and this one).

I'm not a huge fan of the "trance" background music, but the videos do a good job showing what we're up to.

Party Time!!!

For dinner tonight, I had a bowl of popcorn and a cottage-cheese container full of lemonade.

I can't wait until Kla gets home.

Wednesday, February 08, 2012

Free Memory in Ubuntu

I was so happy to figure this out that I wanted to post it for my own memory and anyone else who was also interested.

On one of my computers, my RAM was being eaten up and I couldn't figure out why.  Running 'top' resulted in the following line:

Mem:    505908k total,   478736k used,    27172k free,    41888k buffers

Out of my half gig of ram, 95% was being used.  Browsing the list of processes didn't give any indication that there were any particular memory hogs.

Running 'free -m' (the -m prints in megabyes instead of the default kilobytes) resulted in the following output:

user$ free -m
             total       used       free     shared    buffers     cached
Mem:           494        469         25          0         41        315
-/+ buffers/cache:        112        381


From that, I was able to discover that the majority of my RAM was tied up in caching data.  Not necessarily bad, since if you have spare RAM lying around, you might as well use it for something, but it was slowing down my SSH terminals to the point where they were effectively unusable.  The previous couple times I had this problem, I had simply rebooted, but that was a hammer=nail solution and I wanted a better one.  I finally found the solution on ubuntu-unleashed.com.
  1. Flush file system buffers for safety
    1. user$ sync
  2. Become root (simply sudo-ing the final command won't work because of the redirection)
    1. user$ sudo bash
  3. Free cached memory
    1. root# echo 1 > /proc/sys/vm/drop_caches
To check that Ubuntu had given back my RAM, 'top' resulted in the following:

Mem:    505908k total,   120384k used,   385524k free,      204k buffers

Additionally, 'free -m' resulted in the following:


user$ free -m
             total       used       free     shared    buffers     cached
Mem:           494        128        365          0          0         24
-/+ buffers/cache:        103        390

Tuesday, January 31, 2012

Street Musician

I just watched a very pretty performance by a street musician on YouTube.  Two things in the video struck me:

1. A surprising number of passer-bys put some money into his case.
2. None of them stuck around to listen to the music.

I wonder why? 

Presidental Elections

Right now, if I had to vote for someone for President, and wasn't allowed to abstain, my vote would go as follows:

1. Mitt Romney
2. Barack Obama
2. Rick Santorum
3. Newt Gingrich

I was listening to Mitt Romney's celebration speech (for winning the Florida primary) this evening on the way home from work, and I had to shake my head several times.  Most of it was at the attacking nature of speech: "My opponents are doing this stupid thing!  The president wants to destroy America!"  Other times it was at the black and white nature of the positions he presented.  "The president wants to disband our entire military! I'm going to make it into the greatest military juggernaut in history!" (Yes, I'm exaggerating.)

Apparently Florida has been just about the most negative political race in history.  As a huge believer in decency, respect, and diplomacy, my estimation of Mitt Romney (and the other candidates) has been lowered because of the attack ads they've ran.

At the same time, I know why the candidates run attack ads: they get attention, they get press, and they get results.  People are swayed by them.  The unfortunate side effect is that candidates are willing to run incorrect (read: lying) attack ads, because by the time they're exposed, the damage has been done and of course the expose gets much less attention than the ad itself.

I'm guessing most people in country would agree that the state of politics in our country is pretty bad.  It's hard going to the polls when you're only selecting the least distastful of two choices.

Saturday, December 24, 2011

Year-end Letter

Hello all! In the revered tradition of year-end updates on our lives, we'd like to let everyone know how Drek, Child, and Ash are surviving the punishing, temperate climate of California.

Hanging Christmas lights in the dead of San Diego winter
In a year full of raising a kid, buying a house, and holding down a job, our family's crowning achievement, of course, was getting chickens. Four of them, although only one seems to be laying eggs, and then only once every few days. A few days ago, another chicken made a half-hearted effort leading to a marble-sized egg which was more of hors d'oeuvres than a meal. Lazy chickens. Little do they know that their carefree, freeloading era is near its end. As the old saying goes, "An egg in the fridge is worth two in the chicken." Those who don't produce end up as dinner. Or so Drek's boss tells him on a regular basis.

Speaking of 5D Robotics, Drek has managed to hold down a job for a full year. Even better, he's quelled nearly all the robotic revolutions he's instigated. For those worried about robots taking over the world, don't be—the end will be swift and painless. The company is doing well, having moved to a larger building nearly a 400 foot trek from the old one. The “big bay” itself in the new building is nearly the size of our old digs, with plenty of room to get a robot up to speed before slamming it into a closed door (protip: laser rangefinders do not handle highly absorbent paint well).

As winter approaches, Drek misses his yearly tradition of snow cave camping, but he's taking what solace he can in weekly visits to the beach or early morning outings to the neighborhood Frisbee golf course.
 
Child spent 2011 taking care of a Sunday School class of fourteen teenagers, a new house, a ten-year-old car, a two-year girl, and four chickens. It's totally understandable how confusions could arise, with the occasional chicken sitting up for dinner at the table or Ash locked in the chicken coop on one of her “spirited” days.


The most beautiful woman in the world
Child and Ash took the brunt of the enjoyment of the aforementioned zoo passes, visiting once a month at least. The passes also gained them access to the Safari park, which supplies much of the animals to the San Diego and other zoos.

The future of Humanity
The zoo is located near La Jolla, yet another of the beaches that dot the California landscape. At La Jolla, Child and Drek got to experience scuba diving for the first time, at which Child excelled but which involved a little too much water for Drek's taste (Drek prefers his beaches above sea level and boat engines not leaking oil slicks into his mouth). As beginners, they stayed in a shallow, churned-up lagoon, the theory apparently being that the less visibility there was, the more likely they'd be to want to return in hopes of actually seeing something. They did see a few fish close-up, but they were chance meetings in the murk and as much of a surprise to both diver and fish. Still, they (Drek and Child, not the fish) enjoyed it enough to probably attempt it again—preferably somewhere tropical.


Scuba diving (brochure picture)

Scuba diving (actual picture)
One of Redacted's primary accomplishments was buying their first house. Having had enough of wall-sharing neighbors testing their sound systems at 11 pm at night, upstairs dogs peeing onto their porch, and walking through a fog of cigarette smoke on their way to their car in their Sunday clothes, they decided to leave that world behind for the relaxing, care-free life of a home-owner.
Listing photo of new home in Vista, CA (lawn photoshopped in by real estate company)
The first month in their home, they received a visit from a representative of the water company. They were informed that their home was using enough water to supply a small village and that if they weren't, in fact, operating a clandestine water-park, they might want to get that looked at. As they found out, their home was leaking water underneath the cement foundation, which according to the plumber was “a mite hard to get to.” That's plumber-speak for “we're just going to cut off your pipes at the foundation and route everything through the ceiling instead,” or more succinctly, “Looks like I'm going to Hawaii this year.” Three days and one vacation package to Hawaii later, the Redacteds were able to shower again and reestablish social contact.

A few days later, cleaning up the backyard became a priority when the next-door neighbor asked if the Redacteds were growing marijuana back there (no). A few days later, Drek met the back-fence neighbor and mentioned this anecdote to him with a laugh. The back-fence neighbor didn't laugh. “I grow marijuana. For my injured back, you know. But never around the kids.” Oh, good.

Interesting aspects to home-ownership aside, it's been enjoyable having a garden, chickens, and yes, neighbors at property-line distance. Our backyard is big enough for tents, so everyone is welcome to visit, as long as they don't mind the possibility of a chicken slipping into their sleeping bag with them.

Friday, December 16, 2011

This may be the height of nerdiness, but the sheer length and impenetrableness of the following compiler error message amused me so much I decided to post it.

Yes, it's a single error message, for one line of code:

error: no match for ‘operator&&’ in ‘behaviorOption.std::_Rb_tree_iterator<_Tp>::operator* [with _Tp = std::pair<const int, std::map<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::less<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > > >]()->std::pair<const int, std::map<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::less<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > > >::second.std::map<_Key, _Tp, _Compare, _Alloc>::find [with _Key = std::basic_string<char, std::char_traits<char>, std::allocator<char> >, _Tp = std::basic_string<char, std::char_traits<char>, std::allocator<char> >, _Compare = std::less<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, _Alloc = std::allocator<std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >](((const std::basic_string<char, std::char_traits<char>, std::allocator<char> >&)(& std::basic_string<char, std::char_traits<char>, std::allocator<char> >(((const char*)"reportParams"), ((const std::allocator<char>&)((const std::allocator<char>*)(& std::allocator<char>()))))))) && std::operator== [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>](((const std::basic_string<char, std::char_traits<char>, std::allocator<char> >&)((const std::basic_string<char, std::char_traits<char>, std::allocator<char> >*)behaviorOption.std::_Rb_tree_iterator<_Tp>::operator* [with _Tp = std::pair<const int, std::map<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::less<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > > >]()->std::pair<const int, std::map<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::less<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > > >::second.std::map<_Key, _Tp, _Compare, _Alloc>::operator[] [with _Key = std::basic_string<char, std::char_traits<char>, std::allocator<char> >, _Tp = std::basic_string<char, std::char_traits<char>, std::allocator<char> >, _Compare = std::less<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, _Alloc = std::allocator<std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >](((const std::basic_string<char, std::char_traits<char>, std::allocator<char> >&)(& std::basic_string<char, std::char_traits<char>, std::allocator<char> >(((const char*)"reportParams"), ((const std::allocator<char>&)((const std::allocator<char>*)(& std::allocator<char>()))))))))), ((const char*)"true"))’

"Oh, yes, I clearly see what my mistake was.  Using the C++ Standard Library."