gelldur / EventBus

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

assert failed in processLimit #50

Open penfree opened 1 year ago

penfree commented 1 year ago

I got an exception and the program crashed, i don't really know how to reproduce it, it is not triggered by a special parameter. would you please help me to figure it out. @gelldur

penfree commented 1 year ago

i have gdb into the core.

(gdb) p _eventStreams
$1 = std::vector of length 0, capacity 0
(gdb) p _eventToStream
$2 = std::map with 3 elements = {
  [0x55fad188f928 <dexode::eventbus::internal::type_id_ptr<dolphin::StreamAddEvent>::id>] = 0x55fad26f2510,
  [0x55fad18907f8 <dexode::eventbus::internal::type_id_ptr<dolphin::StreamRemoveEvent>::id>] = 0x55fad26af030,
  [0x55fad1891a48 <dexode::eventbus::internal::type_id_ptr<dolphin::StreamStatusChangeEvent>::id>] = 0x7f4644005fa0}
(gdb) quit
gelldur commented 1 year ago

Hello, could you send more ? I mean parts of your code? I will try to check again this part of code. Thanks. Some questions:

  1. Do you use EventBus in multithreaded environment ? (Send events in one thread, process in another)
  2. Do you call process() in multiple threads?
penfree commented 1 year ago

Hello, could you send more ? I mean parts of your code? I will try to check again this part of code. Thanks. Some questions:

  1. Do you use EventBus in multithreaded environment ? (Send events in one thread, process in another)
  2. Do you call process() in multiple threads?
  1. yes, i use it in multithreaded environment.
  2. yes, every threads postpone and process immediately。

the code is almost the same as readme, except it is called in multithread environment.

gelldur commented 1 year ago

Overall there should be only 1 thread that consumes ( calls process() ). You can send events from any thread ( calling postpone(Event) ). I will try write test for your use-case. I think I didn't tested it like that.

Usually you have 1 consumer thread for example main thread that will process events and call your listeners. Thanks to that you always know on what thread you listeners would be executed.

penfree commented 1 year ago

Overall there should be only 1 thread that consumes ( calls process() ). You can send events from any thread ( calling postpone(Event) ). I will try write test for your use-case. I think I didn't tested it like that.

oh, that is not easy to do. so i should use a cycle thread to consume the events?

gelldur commented 1 year ago

Ok nvm, I will create test for this. Maybe there is a bug.

In source code I see there is already mutex for "single process"

std::lock_guard writeGuardProcess{_mutexProcess}; // Only one process at the time
penfree commented 1 year ago

Ok nvm, I will create test for this. Maybe there is a bug.

In source code I see there is already mutex for "single process"

std::lock_guard writeGuardProcess{_mutexProcess}; // Only one process at the time

emm, i saw that too, so maybe mutex is missed somewhere. i found that when call frequency is slow, it works well

gelldur commented 1 year ago

Thanks, I will find issue and fix it soon (I will try this weekend). My best guess for now that there is some data race between process() and postpone()

penfree commented 1 year ago

@gelldur is there any progress?

gelldur commented 1 year ago

Sorry didn't have time. I will try soon. If you find solution It would be nice to merge your PR :)