gelldur / EventBus

A lightweight and very fast event bus / event framework for C++17
Apache License 2.0
370 stars 81 forks source link

Fix single-threaded event-loop deadlock by using recursive_mutex #30

Closed travishaagen closed 4 years ago

travishaagen commented 5 years ago

Fixed single-threaded event-loop deadlock by using recursive_mutex for AsyncEventBus's _callbacksMutex.

A single thread executed the event loop:

        while (!stop)
        {
            if (bus.waitFor(timeout))
            {
                bus.consume(100);
            }
        }

I discovered that when an event-handler was invoked that a deadlock would occur when I put another event on the bus from within that same event-handler callback method. With this change it works.

gelldur commented 5 years ago

Thanks! I will prepare test shortly and I will merge. I need to check this also with develop branch as some big changes are happening :)

gelldur commented 4 years ago

Hey so I revived your PR. I think that your fix can introduce other type of issues. I prepared proper test for this case on the development branch. New approach how EventBus should work eliminate this issue.

Other issues that I see: