0

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?

1 Answer 1

1

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.

3
  • 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. Commented Jan 31, 2017 at 9:10
  • Sounds good. All the very best Commented Jan 31, 2017 at 9:17
  • Thanks, will update the answer when I make the implementation. Commented Jan 31, 2017 at 10:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.