views:

370

answers:

3

I'm looking for something to abstract the standard operating system functionality in C/C++: span/kill a thread, send/receive a message, start/stop a timer, maybe even memory management, although I can probably handle that myself with my own buffer pool.

I want to to be able to develop and unit test on Linux/windows and then recompile the c/c++ code for various target O/Ses (for embedded systems: eCos, FreeRTOS, VxWorks, etc)

Something as "light" as possible would be best, hopefully just a library, maybe even a collection of macros.

Thanks in advance for any help.

+6  A: 

Have you looked at the Boost library? It has threads, timers, memory management, and a signals library.

The library is not a small download, but most of the library components are header-only implementations (though the OS abstraction libraries tend to have to be linked), and you only have to use what you need.

James McNellis
mawg
I also support Boost as a very good option to abstract OS basic mechanishmTake a look to Interprocess, Thread and ASIO library
HyLian
There are Boost libraries for threads (Boost Thread), interprocess messaging (Boost Interprocess), and timers (Boost Timer). Memory management is a rather broad topic, but Boost has various containers and smart pointers for memory management. It will definitely compile and run on Linux, Windows, Mac OSX, and BSD. It will probably run on a lot of embedded OSes. As for whether the libraries are lean and efficient, it all depends on how you define "lean" and "efficient."
James McNellis
Boost is beginning to look very good ... thanks, all
mawg
You're welcome, mawg. Good luck.
James McNellis
+2  A: 

Why don't you directly call only POSIX functions (POSIX1 seems to fill all your needs) and install a POSIX layer above non-compliant operating system (to be read as Microsoft Windows)?

ntd
Microsoft Windows has been POSIX compliant since NT, it just returned the equivalent of 'not implemented' for every function where that's an option; unfortunately POSIX allows that for so many functions that being POSIX compliant doesn't necessarily mean usable, hence the need for a compatibility layer.
Pete Kirkham
A: 

I think boost is worth to look into; it can provide you an os abstraction, but also a compiler independence, and much, much more. It does require C++ of course. Other options: Posix.

In your list:
eCos, VxWorks, Linux : good posix support, so you can use this. freertos: see link

Windows lacks good posix support out of the box (see wikipedia Posix) If cygwin is ok for you, you can propably use it. If you need to mix with Visual Studio, a library like boost seems more interesting (you'd abstract away from it)

Adriaan