0

In C++ boost libraries, there are synchronization mechanisms provided, which however support only a very limited list of compilers.

We have to implement the synchronizaion mechanisms in our own way so that it provides wider support for different compilers. In other words, we want to write multi-platform C++ libraries.

I'm pretty new to multiplatform programming and the C++ realm (previously a Java guy). Could someone please show me how to get started possibly with some simple examples?

Terry Li
  • 16,870
  • 30
  • 89
  • 134

3 Answers3

3

Although Boost might not provide a ready made solution for you, it incorporates a lot of information and tools to deal with different compilers. I suggest you check out how they manage it and see if you can leverage some of their code. In your place I'd start with Boost.Config.

Nicola Musatti
  • 17,834
  • 2
  • 46
  • 55
1

For Windows, use events and critical sections. For UNIXy platforms, use pthreads mutexes and condition variables. These should work on any compiler that supports those platforms.

What compilers do you need to support? Boost's synchronization methods support almost every compiler you're likely to use including GCC, Intel's C++ compiler and Microsoft Visual Studio.

David Schwartz
  • 179,497
  • 17
  • 214
  • 278
  • You're right, but my boss told me that's not enough and wanted me to extend it to provide wider support for compilers. – Terry Li Nov 01 '11 at 21:28
  • Ask him which compilers he wants you to support. – David Schwartz Nov 01 '11 at 21:39
  • The only other ones I could imagine wanting to support would be [clang](http://en.wikipedia.org/wiki/Clang) (which seems to compile boost) and [Comeau](http://en.wikipedia.org/wiki/Comeau_C/C%2B%2B) (I think it compiles boost). I haven't heard of anyone using any other compiler in the last several years. – Mooing Duck Nov 01 '11 at 22:11
  • @DavidSchwartz CentOS for example? The goal is: write one piece of code that works for everything. – Terry Li Nov 02 '11 at 18:35
  • @TerryLiYifeng: That's not a sensible goal. That's part of the reason so much software works so poorly and unreliably on some platforms. There's a "right way" to do things on some platforms, and they're not all the same. And there's no way you can know *today* what the right way will be on a platform that doesn't even exist yet. If you want the most portable we can make one chunk of code today, just use Boost. That's its goal, and you're unlikely to be able to do it better than they do. – David Schwartz Nov 02 '11 at 22:09
0

Boost has already worked out the design concepts to be able to map both posix and windows synchronization into a consistent interface across several compilers. Have you considered extending the boost framework to work on your desired platforms?

totowtwo
  • 2,101
  • 1
  • 14
  • 21