www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - LibEvent, signals or communication between threads

reply "Shadow_exe" <shadow_exe ukr.net> writes:
Hello everyone.
Faced with an interesting challenge, and how to solve it and 
found no tracks.
The problem is the following:
I have 2 thread, which are created in the main flow, 
respectively, of each other, they do not know, but I want to 
create a dialogue between the thread. I want to first thread 
could tell the second thread to perform some function.
The queue is implemented through a library libevent.

Who faced a similar problem or just knows how to solve this issue 
- please help.
May 08 2012
next sibling parent reply Gor Gyolchanyan <gor.f.gyolchanyan gmail.com> writes:
Try looking at std.concurrency.
You'll find a message passing mechanism there.

On Tue, May 8, 2012 at 2:25 PM, Shadow_exe <shadow_exe ukr.net> wrote:
 Hello everyone.
 Faced with an interesting challenge, and how to solve it and found no
 tracks.
 The problem is the following:
 I have 2 thread, which are created in the main flow, respectively, of each
 other, they do not know, but I want to create a dialogue between the thread.
 I want to first thread could tell the second thread to perform some
 function.
 The queue is implemented through a library libevent.

 Who faced a similar problem or just knows how to solve this issue - please
 help.

-- Bye, Gor Gyolchanyan.
May 08 2012
parent reply sclytrack <sclytrack iq87.fr> writes:
On 05/08/2012 04:29 PM, Gor Gyolchanyan wrote:
 Try looking at std.concurrency.
 You'll find a message passing mechanism there.

 On Tue, May 8, 2012 at 2:25 PM, Shadow_exe<shadow_exe ukr.net>  wrote:
 Hello everyone.
 Faced with an interesting challenge, and how to solve it and found no
 tracks.
 The problem is the following:
 I have 2 thread, which are created in the main flow, respectively, of each
 other, they do not know, but I want to create a dialogue between the thread.
 I want to first thread could tell the second thread to perform some
 function.
 The queue is implemented through a library libevent.

 Who faced a similar problem or just knows how to solve this issue - please
 help.


Andrei's "Concurrency in the D programming language". You can google it. http://www.informit.com/articles/article.aspx?p=1609144&seqNum=7
May 08 2012
parent =?UTF-8?B?QWxpIMOHZWhyZWxp?= <acehreli yahoo.com> writes:
On 05/08/2012 09:00 AM, sclytrack wrote:
 On 05/08/2012 04:29 PM, Gor Gyolchanyan wrote:
 Try looking at std.concurrency.
 You'll find a message passing mechanism there.

 On Tue, May 8, 2012 at 2:25 PM, Shadow_exe<shadow_exe ukr.net> wrote:
 Hello everyone.
 Faced with an interesting challenge, and how to solve it and found no
 tracks.
 The problem is the following:
 I have 2 thread, which are created in the main flow, respectively, of
 each
 other, they do not know, but I want to create a dialogue between the
 thread.
 I want to first thread could tell the second thread to perform some
 function.
 The queue is implemented through a library libevent.

 Who faced a similar problem or just knows how to solve this issue -
 please
 help.


Andrei's "Concurrency in the D programming language". You can google it. http://www.informit.com/articles/article.aspx?p=1609144&seqNum=7

I have written a chapter about the same: http://ddili.org/ders/d.en/concurrency.html Although not directly related, the "Thread names" title there has an example where two threads discover each other by their names. Ali -- D Programming Language Tutorial: http://ddili.org/ders/d.en/index.html
May 08 2012
prev sibling next sibling parent "Shadow_exe" <shadow_exe ukr.net> writes:
Yes, there is some communication between the thread, but it is 
locked and the thread waits for him not come something like a 
signal.
My task is not to block the trade and send a signal in this 
thread.

On Tuesday, 8 May 2012 at 14:29:37 UTC, Gor Gyolchanyan wrote:
 Try looking at std.concurrency.
 You'll find a message passing mechanism there.

 On Tue, May 8, 2012 at 2:25 PM, Shadow_exe <shadow_exe ukr.net> 
 wrote:
 Hello everyone.
 Faced with an interesting challenge, and how to solve it and 
 found no
 tracks.
 The problem is the following:
 I have 2 thread, which are created in the main flow, 
 respectively, of each
 other, they do not know, but I want to create a dialogue 
 between the thread.
 I want to first thread could tell the second thread to perform 
 some
 function.
 The queue is implemented through a library libevent.

 Who faced a similar problem or just knows how to solve this 
 issue - please
 help.


May 08 2012
prev sibling next sibling parent Sean Kelly <sean invisibleduck.org> writes:
On May 8, 2012, at 3:25 AM, "Shadow_exe" <shadow_exe ukr.net> wrote:

 Hello everyone.
 Faced with an interesting challenge, and how to solve it and found no trac=

 The problem is the following:
 I have 2 thread, which are created in the main flow, respectively, of each=

. I want to first thread could tell the second thread to perform some functi= on.
 The queue is implemented through a library libevent.
=20
 Who faced a similar problem or just knows how to solve this issue - please=

If you're already using libevent you can either send the message via a socke= t or send the message using std.concurrency and then signal the other thread= by writing to a socket it's reading. You can call receiveTimeout(0) to not b= lock on receive.=20=
May 08 2012
prev sibling next sibling parent "Shadow_exe" <shadow_exe ukr.net> writes:
Thank You! As would there sometimes You have helped.
But I'm afraid that these methods me not suitable because 
libevent already creates a queue and turn me not to come out to 
do.
Information how to send that is the signal to the next thread I 
have not found this information that have been granted to You - 
I've read.

Okay, I will do through юниксовые sockets.


On Tuesday, 8 May 2012 at 17:09:53 UTC, Ali Çehreli wrote:
 On 05/08/2012 09:00 AM, sclytrack wrote:
 On 05/08/2012 04:29 PM, Gor Gyolchanyan wrote:
 Try looking at std.concurrency.
 You'll find a message passing mechanism there.

 On Tue, May 8, 2012 at 2:25 PM, 
 Shadow_exe<shadow_exe ukr.net> wrote:
 Hello everyone.
 Faced with an interesting challenge, and how to solve it and 
 found no
 tracks.
 The problem is the following:
 I have 2 thread, which are created in the main flow, 
 respectively, of
 each
 other, they do not know, but I want to create a dialogue 
 between the
 thread.
 I want to first thread could tell the second thread to 
 perform some
 function.
 The queue is implemented through a library libevent.

 Who faced a similar problem or just knows how to solve this 
 issue -
 please
 help.


Andrei's "Concurrency in the D programming language". You can google it. http://www.informit.com/articles/article.aspx?p=1609144&seqNum=7

I have written a chapter about the same: http://ddili.org/ders/d.en/concurrency.html Although not directly related, the "Thread names" title there has an example where two threads discover each other by their names. Ali

May 08 2012
prev sibling parent Sean Kelly <sean invisibleduck.org> writes:
On May 8, 2012, at 11:13 AM, Shadow_exe wrote:

 Thank You! As would there sometimes You have helped.
 But I'm afraid that these methods me not suitable because libevent =

 Information how to send that is the signal to the next thread I have =

=20
 Okay, I will do through =D1=8E=D0=BD=D0=B8=D0=BA=D1=81=D0=BE=D0=B2=D1=8B=

std.concurrency uses a condition variable internally to signal the = waiting thread when new messages have arrived. As this is an = implementation detail, it isn't exposed to the user. libevent is unfortunately somewhat limited in the events that can be = monitored. It's pretty much just read/write events on a file = descriptor, so using a socket or pipe is about the only way to notify a = thread blocked on a libevent queue. libev is more flexible in the range = of events it offers. I believe there's even a user-triggered event, = though I bet this still uses a pipe internally. And you're still stuck = with the problem of sending the message and then separately triggering = the event. Really, messaging doesn't seamlessly integrate with high-performance = socket IO. Once Phobos gets a better networking API I'd like to provide = a shim to proxy data to/from a socket Erlang-style, but that approach is = really only desirable for simple cases, and cases where performance = isn't a significant concern (since it tends to involve a lot of memory = churn). Beyond that=E2=80=A6 maybe I can cook up some way to let the = user plug a notification mechanism into the message queue, so when a = message is received, if nothing is waiting on the condition variable the = other notification mechanism is used instead.=
May 08 2012