[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[Libevent-users] Multithreading and breaking out of the event loop
- To: libevent-users@xxxxxxxxxxxxx
- Subject: [Libevent-users] Multithreading and breaking out of the event loop
- From: George-Theodor Serbana <theodor.serbana96@xxxxxxxxx>
- Date: Tue, 12 Feb 2019 14:44:35 +0200
- Delivered-to: archiver@xxxxxxxx
- Delivered-to: libevent-users-outgoing@xxxxxxxx
- Delivered-to: libevent-users@xxxxxxxx
- Delivery-date: Tue, 12 Feb 2019 07:44:50 -0500
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=Ijw8kuwHTirFDNJ1SaxGNhHNrfH++baYxmJAJjT6WXw=; b=K/5HRi0Q39vt+khL6AOEe+KGphkjCoWijG12rya7UwGPkqz0kNYZL/e0KH0hCzc8fR sGiWimTnZKXld2TnoXNMFwbMQa6/5FqAPY1BhcZvUcrR4KQadr9mwd/cYU0DUkadBdBR tSwSMO01dNUkMXfk0B5xR0aDEL+ZkHoPLMHObLnt8SwirL2/HwDFIzm4yYtolrSSz4dR 2JWpmKkRH/n143p+p0jGsUCqJibr8F48oU3jlRuBO3PNSYzRfUL9ExEelX+9Lqbk4BqN OjzFmQES1fYsBIHl51x4MYgpok75Exwin1+gg3uqUE7V2T35Fn/TihOifnYQ5YTZ5Jh5 0Frg==
- Reply-to: libevent-users@xxxxxxxxxxxxx
- Sender: owner-libevent-users@xxxxxxxxxxxxx
Hi,
I have a C++ program interacting with a C static library that is
internally using libevent.
I am able to break out of the C lib's libevent main loop but the exact
order in which threads are executing worries me.
The full details and question can be found here:
https://stackoverflow.com/questions/54589066/multithreading-in-libevent
Regards,
Theodor
For ease, I will copy and paste the StackOverflow question here as well:
--------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------
I have one thread (Thread A) in a C static library that's creating the
libevent event_base after doing this:
#ifdef WIN32
evthread_use_windows_threads();
#else
evthread_use_pthreads();
#endif
This C static library is all single threaded and it's doing all the
libevent work itself: adding events, dispatching, main loop, etc, all
these being done from Thread A.
Now I have a C++ program that I link with the library above, calling
the entrance function into the C library from a boost::thread called
Thread B.
At some point into my C++ program, I have yet another boost::thread
called Thread C which will attempt to event_add using the C library
into Thread A's event loop and then immediately call event_active.
What I'd like to see after doing stuff from Thread C is this:
calling event_add from Thread C
calling event_active from Thread C
Processing events from Thread A
calling the event's handler from Thread A
Possibly we could have Processing events from Thread A anywhere else
between those lines, but for sure we must have at least 1 such line
between event_active and event handler execution, right?
What I see instead is this:
calling event_add from Thread X
calling event_active from Thread X
calling the event's handler from Thread A
Thread X is a different ID than Thread C but I guess that's just
because of using boost threads in the C++ calling site and pthreads in
the C library or something, anyways it doesn't bother me.
I also like the fact that my main purpose here is OK: firing the event
from a thread and handling it from another.
But for my own curiosity what I don't understand is why I don't see a
line "processing events from Thread A" before the handler callback is
called?
Thread ids were gotten with pthread_self(), this was tested on Linux,
more specifically Ubuntu 18.04.
***********************************************************************
To unsubscribe, send an e-mail to majordomo@xxxxxxxxxxxxx with
unsubscribe libevent-users in the body.