I'm developing a framework with C++, and it contains three layers:

  • Low level functions which do the hard work
  • An upper layer which uses the low level functions to accomplish tasks (functions at this level generally uses only one lower level function and explicitly accepts the pointer of the function to know which function to call)
  • Top level classes which utilizes these middle layer functions to accomplish complete tasks.

The problem is, I'm introducing concurrency into the framework and need a way to tune this concurrency per function basis. I can design an object to transfer concurrency parameters, but I don't want to pass an object to functions which are not concurrent.

Concurrent functions can be at any level and their concurrency needs to be controlled independently.

Is there a better pattern or method to allow only concurrent functions to access this information?


Have you tried boost.fiber ? This is a userspace thread framework(sort of like green threads)

I haven't personally used it, but if I understand well, boost fibers can provide you with the level of granularity you need without the overhead of switching between threads.

So you can maybe spawn the concurrent functions as fibers under the thread that's owned by the parent, isolating the concurrency information within the thread/s.

You can even use different types of fiber management for different sets of functions.Hence good tunability.

  • Thanks, I will keep that in my mind. I've implemented most of the framework, hence re-implementing a great chunk will not be very practical at this point. While thinking I've found way, which stores threading policies inside a namespace and a thin library that manages the threading policies. A function can get a special or default policy if it needs to from the namespace. If it doesn't need policies or threading, there's no need to modify it. – bayindirh Jan 31 '17 at 9:10
  • Sounds good. All the very best – Naresh Kumar Jan 31 '17 at 9:17
  • Thanks, will update the answer when I make the implementation. – bayindirh Jan 31 '17 at 10:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.