| Thread overview | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
May 08, 2012 LibEvent, signals or communication between threads | ||||
|---|---|---|---|---|
| ||||
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 Re: LibEvent, signals or communication between threads | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Shadow_exe | 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 Re: LibEvent, signals or communication between threads | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Gor Gyolchanyan | 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 Re: LibEvent, signals or communication between threads | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Shadow_exe | 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 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.
If you're already using libevent you can either send the message via a socket 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 block on receive.
| |||
May 08, 2012 Re: LibEvent, signals or communication between threads | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Gor Gyolchanyan | 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 Re: LibEvent, signals or communication between threads | ||||
|---|---|---|---|---|
| ||||
Posted in reply to sclytrack | 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 Re: LibEvent, signals or communication between threads | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Ali Çehreli | 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 09, 2012 Re: LibEvent, signals or communication between threads | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Shadow_exe | 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 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.
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… 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.
| |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply