Saturday, March 30, 2013

Configuring swap space in a Raspberry Pi

Recently I found myself needing to increase the amount of swap space available in my Raspberry Pi. My Pi runs a Raspbian (Wheezy), and I was trying to compile phantomjs because none of the available binaries seem to work for me:

https://github.com/piksel/phantomjs-raspberrypi
https://github.com/aeberhardo/phantomjs-linux-armv6l

Aeberhardo's project provides instructions on how to compile your own phantomjs in your Pi. Anyway, one of the compilation steps was failing and I noticed the problem was my Pi was running out of memory. Initially it is configured to use 100Mb of swap space, and I needed more.

Raspberry Pi uses a disk based swap solution called dphys-swapfile . To configure the swap space you just have to edit the file /etc/dphys-swapfile:

CONF_SWAPSIZE=[size in mb]

and restart the swap daemon:

/etc/init.d/dphys-swapfile stop
sudo /etc/init.d/dphys-swapfile start

There you go, now you are all set with an expanded (or reduced) swap space. Be aware that swap on the Pi is tremendously slow, and that it reduces the life of the SD card, since SD cards have a limited number of write operations that can be performed on them before they stop working.

I hope this helps!

Enjoy your Raspberry Pi!!!

Tuesday, March 26, 2013

Concurrency in C++11

A quick post to express my surprise about the new (standard) concurrency library part of the new C++11 standard.

Coming from a strong Java background I felt at home as soon as I started reading about it:
 * Futures?
 * Condition variables?
 * Promises?

It really looks and feels like the high level concurrency facilities provided by Java, but without all the boilerplate that is ALWAYS necessary when dealing with Java:

I have found a nice introduction to the library here:

http://www.justsoftwaresolutions.co.uk/threading/multithreading-in-c++0x-part-1-starting-threads.html

No for novices though. You'll need a solid understanding of concurrency concepts to enjoy the reading.

Enjoy!!!