bitshares-fc icon indicating copy to clipboard operation
bitshares-fc copied to clipboard

Boost fiber

Open pmconrad opened this issue 5 years ago • 3 comments

Proof-of-concept for switching fc::thread to boost::fibers . Replaces fc::do_parallel with boost::fibers constructs. Related tests are working. ~~Still much to do.~~ Requires Boost-1.62+. ~~boost::fibers contains a memory leak in algorithm_with_properties that still needs to be worked around.~~

pmconrad avatar Oct 10 '19 06:10 pmconrad

Boost.Fiber depends upon Boost.Context. Boost version 1.61.0 or greater is required.

Ubuntu 16 users would need to build boost by themselves.

abitmore avatar Oct 10 '19 11:10 abitmore

Yes. I think by the time this gets into production Ubuntu-20.04 will be out. We can consider bumping requirements to Boost-1.62 and C++17 then.

pmconrad avatar Oct 10 '19 11:10 pmconrad

Got rid of the memory leak. All tests working locally.

There are some key differences to the old fc::thread implementation:

  • A thread that wants to receive async task assignments from other threads must call fc::initialize_fibers() first.
  • A task that is being pushed into another thread will only be pushed when the current fiber yields.
  • A thread that still has fibers in its queue will not terminate, even if the "main" fiber exits. This is particularly nasty for background fibers started from the main thread - they will prevent the program from exiting, even if the main fiber has left main().
  • Unlike fc::task, there is no support for cancelling a fiber. A means to cancel a task that is scheduled in the background must be implemented separately. Due to this, fc::schedule should not be used with a time in the far future.
  • boost::fiber synchronization mechanisms (mutexes and condition variables) do not work in destructors of objects with static lifetime.

pmconrad avatar Nov 15 '19 10:11 pmconrad