4

I was just wondering, is any implementation of an event loop bound to platform specific code?

By event loop, I'm referring to a simple thread that is checking a queue, working with messages and dispatches appropriately to callbacks.

Because I simply don't see how I'd be able to write one without having to use for examples:

-A semaphore/mutex/event object/Sleep() [windows].

Which of course, the above are not the same for every operating system.

This is for C/C++ by the way.

Andy Carter
  • 201
  • 3
  • 12

1 Answers1

1

A few portable, cross platform C++ frameworks have an event queue implemented, for example ACE Reactor framework. Another example is Qt.

piokuc
  • 25,594
  • 11
  • 72
  • 102
  • Well of course - even C++11 has a multiplatform threading capability derived from boost - but aren't they just wrappers made with conditional compilation? – Andy Carter Dec 16 '13 at 11:25
  • Certainly, a cross-platform C++ code working with threads and synchronization mechanisms will need to involve some conditional compilation. But is that a problem? You will not need to write a single `#ifdef` yourself, all the conditional code is wrapped inside the frameworks. – piokuc Dec 16 '13 at 11:29
  • Nope, it isn't a problem. I just wanted to confirm my assumptions. Many thanks! – Andy Carter Dec 16 '13 at 11:34
  • Just wanted to add that if you can see how to achieve what you need using C++11 features and/or BOOST, plus you know you can use C++11 and/or BOOST on your target platforms, then go for it! – piokuc Dec 16 '13 at 11:37
  • My initial idea was to write it from scratch. Make my own event loop and do conditional compilation. So - something along the lines of writing my own event library so to say. – Andy Carter Dec 16 '13 at 12:13