2

I am new to atomic variables. I am trying to modify this C++ file to break out the benchmark_rx_rate function in its own file so I can use it in my project.

The main file has a bunch of std::atomic_ullong type variables for logging which I want to preserve. My ideal situation would be to define some struct of all the std::atomic_ullong I need in a benchmark_rx_rate.h, initialize it when I need it, and to pass through to my new benchmark_rx_rate function in a benchmark_rx_rate.cpp file.

On line 573 is where the function gets called, like so:

auto rx_thread = thread_group.create_thread([=, &burst_timer_elapsed]() {
                    benchmark_rx_rate(usrp,
                        rx_cpu,
                        rx_stream,
                        spb,
                        random_nsamps,
                        start_time,
                        burst_timer_elapsed,
                        elevate_priority,
                        rx_delay);
                });

I am starting small just trying to pass through the num_overruns variable which is a std::atomic_ullong. I have tried what was suggested here. I am now getting an error saying:

use of deleted function β€˜std::atomic<long unsigned int>::atomic(const std::atomic<long unsigned int>&)

What is the best practice for providing am atomic variable to a function that will modify it, if the function is called through a lambda? How would the process differ from passing just a single atomic variable versus passing a struct of atomic variables?

zack komo
  • 45
  • 2
  • 3
    Just capture `num_overruns` by reference like you do with `burst_timer_elapsed`? – Yksisarvinen Apr 21 '23 at 19:50
  • 2
    The message says that you cannot copy an atomic variable, which you wouldn't want to anyway. – BoP Apr 21 '23 at 20:03
  • @Yksisarvinen I didn't notice that was also atomic.. Thanks! I am also new to lambdas and didn't realize that you capture by reference like that. – zack komo Apr 21 '23 at 20:25

0 Answers0