Monday, July 14, 2008

xchg

The magic to mutexes (or mutices) lies in the xchg instruction.

I've always been wondering how the O/S kernel can actually implement atomic operations until I read some of the 15-410 Operating Systems class slides to realise this little trick.

Hmm... kernels. Maybe I should write a "modern" kernel as a side project some day.

4 comments:

Danielle said...

There's a number of other commands, such as xadd (exchange and add) that can be preceded by the "lock" instruction to ensure that they're atomic operations. It's all pretty snazzy stuff.

The_Laptop said...

Oooo... those too, I almost forgot.

Now I'm starting to kick myself in the butt for not having a partner for O/S...

This might become one of the biggest regrets that I've ever had.

Danielle said...

It's not too late to find a partner... you really should consider it. If nothing else, it means you have someone to split debugging and boring, repetitive work with. It's also really useful to have someone to bounce design decisions off of before you commit to implementing something.

The_Laptop said...

It's practically impossible for this upcoming semester... maybe I can do O/S for my last semester, where things are [hopefully] less stressful on the other fronts.

But then again, I could also just write my own kernel on the side and not be limited by the course heheheh...