[USRP-users] Using a sleep function after receiving data from USRP

Fernando Quivira quivira.f at husky.neu.edu
Mon Feb 4 12:37:26 EST 2013


Great! thanks, Josh.

Do you know which examples use threads? The examples in the example folder
use thread priority, or one thread for rx and one for tx. I haven't seen
one that receives data in one thread, and process in other threads. I don't
know if you are familiar with boost threads, but basically, I have this:

global variables:

boost::condition_variable cond;
boost::mutex mut;

member variables:

std::vector<double> buffer
std::vector<bool> data_ready       // Size equal to number of threads

data receiver loop (1 thread runs this):

while (!gotExitSignal()){
    if(!any(data_ready))
    {
        receive_data(buffer);
        boost::lock_guard<boost::mutex> ll(mut);
        set_true(data_ready);
        cond.notify_all();
    }       }

data processing loop (N threads run this)

while (!gotExitSignal()){
    // boost::unique_lock<boost::mutex> ll(mut);
    boost::mutex::scoped_lock ll(mut);
    cond.wait(ll);

    process_data(buffer);

    data_ready[thread_id] = false;}

These two loops are in their own member functions of the same class. The
variable buffer is a member variable, so it can be shared across threads.
The receiver thread will be launched first. The data_ready variable is a
vector of bools of size N. data_ready[i] is true if data is ready to be
processed and false if the thread has already processed data. The function
any(data_ready) outputs true if any of the elements of data_ready is true,
and false otherwise. The set_true(data_ready) function sets all of the
elements of data_ready to true. The receiver thread will check if any
processing thread still is processing. If not, it will fetch data, set the
data_ready flags, notify the threads, and continue with the loop which will
stop at the beginning until processing is done. The processing threads will
check their respective data_ready flag to be true. Once it is true, the
processing thread will do some computations, set its respective data_ready
flag to 0, and continue with the loop

Thanks

- Fernando

On Mon, Feb 4, 2013 at 12:30 PM, Josh Blum <josh at ettus.com> wrote:

>
>
> On 02/04/2013 11:26 AM, Fernando Quivira wrote:
> > Hi all:
> >
> > I want to use UHD in a multithreaded aplication. Basically, I want a
> thread
> > to handle getting data from the USRP and other threads handling
> processing.
> > In order to have the timings correctly, should I add a sleep statement
> > every time I receive data from the USRP? or is the recv method blocking
> in
> > that regard?
>
> The recv call is a blocking call with a timeout.
> Definitely do not sleep :-)
>
> Also, a few of the examples in host/examples use threads, if you want to
> see demonstration.
>
> -josh
>
>
> >
> > Thanks
> >
> > - Fernando
> >
> >
> >
> > _______________________________________________
> > USRP-users mailing list
> > USRP-users at lists.ettus.com
> > http://lists.ettus.com/mailman/listinfo/usrp-users_lists.ettus.com
> >
>
> _______________________________________________
> USRP-users mailing list
> USRP-users at lists.ettus.com
> http://lists.ettus.com/mailman/listinfo/usrp-users_lists.ettus.com
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ettus.com/pipermail/usrp-users_lists.ettus.com/attachments/20130204/da2d4b31/attachment-0002.html>


More information about the USRP-users mailing list