[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Multithreading in GR blocks
From: |
Marcus Müller |
Subject: |
Re: Multithreading in GR blocks |
Date: |
Mon, 13 Apr 2020 20:07:22 +0200 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.6.0 |
Hi Moses,
ah sorry, I was misreading your code!
Looking at this yes, classical socket programming problem:
Looks like your ListenLoop probably simply hangs on `accept`; that's
because the socket is in blocking mode by default.
So, you'd "simply" do the following:
1. prepare your socket as done in Setup(), but make it non-blocking.
2. in your ListenLoop use `select()`, which blocks, on the socket fd
3. When select() returns:
a.
try to accept(). That can either work instantly (then, select()
finished because there was a connection ready to be accepted), or fail
instantly (because select() finished for any other reason, e.g. the
socket being closed)
b. check whether the socket is still open && !m_bFinished
Or don't. Honestly, writing another TCP socket acceptor in 2020 does
sound like a somewhat tedious thing to do ;) Look at GNU Radio's
gr-network in-tree component, it should have everything you need.
Best regards,
Marcus
On 13.04.20 19:21, Moses Browne Mwakyanjala wrote:
> Hi Marcus,
> I was trying to emulate how the ZMQ block handles multithreading.
> Basically, the ZMQ block overrides the stop() function and joins the
> threads. This is the same thing I tried to do to stop the receive and
> listen threads. Is there any other way of doing this?
>
> bool
>
> TCPServer::stop()
>
> {
>
> m_bFinished=true;
>
> m_ReceiveThread->join();
>
> m_ListenThread->join();
>
> returntrue;
>
> }
>
> Regards,
>
> Moses.
>
>
> On Mon, Apr 13, 2020 at 7:11 PM Marcus Müller <address@hidden
> <mailto:address@hidden>> wrote:
>
> Hi Moses,
>
> your code doesn't show how your GNU Radio block's stop() function would
> tell your TCP Server thread that it's time to shut down, so I presume
> that doesn't happen – that would explain why the flow graph can't ever
> shut down!
>
> Best regards,
> Marcus
>
> On 13.04.20 18:54, Moses Browne Mwakyanjala wrote:
> > Hello everyone,
> > I have created a TCP/IP block by adapting the ZMQ message pub block.
> > Both blocks make use of boost multithreading. The TCP/IP block is used
> > by a standalone C++ program. To run the gnuradio topblock, the C++
> > program calls tb->start() function. To stop the topblock, the
> > functions tb->stop() and tb->wait() are called.However, the program
> > "hangs" when tb->stop() is called. This suggests there is something
> > wrong with the way I use boost multithreading.
> > All help is appreciated.
> >
> > Regards,
> > Moses.
>