c++ - argument of type 'void* (...)(void*)' does not match 'void* (*)(void*) -
c++ - argument of type 'void* (...)(void*)' does not match 'void* (*)(void*) -
i'm developing bloc on gnu radio , want utilize thread. thread there acquired info udp socket can utilize in gnu radio bloc. "general work" function 1 signal , info processing.
the master source file organized :
namespace gr { namespace adsb { out::sptr out::make() { homecoming gnuradio::get_initial_sptr (new out_impl()); } /* * udp thread */ void *task_udprx (void *arg) { while(true) { printf("task udprx\n\r"); usleep(500*1000); } pthread_exit(null); } /* * private constructor */ out_impl::out_impl() : gr::block("out", gr::io_signature::make(1, 1, sizeof(int)), gr::io_signature::make(1, 1, sizeof(char))) { pthread_t thread_udprx; //thread init if(pthread_create(&thread_udprx, null, task_udprx, null)) { err("pthread error"); } else { printf("udp thread initialization completed\n\r"); } } /* * our virtual destructor. */ out_impl::~out_impl() { } void out_impl::forecast (int noutput_items, gr_vector_int &ninput_items_required) { ninput_items_required[0] = noutput_items; } int out_impl::general_work (int noutput_items, gr_vector_int &ninput_items, gr_vector_const_void_star &input_items, gr_vector_void_star &output_items) { const int *in = (const int *) input_items[0]; char *out = (char *) output_items[0]; // <+signal processing+> for(int = 0; < noutput_items; i++) { printf("general work\n\r"); }/* < noutput_items */ // tell runtime scheme how many input items consumed on // each input stream. consume_each (noutput_items); // tell runtime scheme how many output items produced. homecoming noutput_items; } /* general work */ } /* namespace adsb */ } /* namespace gr */`
the problem when seek compile, error :
in constructor ‘gr::adsb::out_impl::out_impl()’: error: argument of type ‘void* (gr::adsb::out_impl::)(void*)’ not match ‘void* (*)(void*)’
this error refers line , concerns task_udprx :
if(pthread_create(&thread_udprx, null, task_udprx, null))
does have thought ?
don't hesitate inquire more details if needed. code i've displayed shortest in order best understanding possible.
thank !
you can't pass pointer fellow member function pthread_create()
.
you'll need free function:
void *thread_start(void *object) { gr::adsb::out_impl *object = reinterpret_cast<gr::adsb::out_impl *>(object); object.task_updrx(0); homecoming 0; }
or thereabouts, , you'll need pass function pthread_create()
, pass this
pointer info argument:
if (pthread_create(&thread_udprx, null, thread_start, this))
i reserve right misusing reinterpret_cast<>()
— substitute right cast notation. have reservations starting thread in constructor, outline of scheme should work.
the code still not mcve. can't re-create , compile it. there many headers missing. types out
, out_impl
not defined/declared. of gnu radio inheritance stuff left out.
here's version of mcve. isn't perfect because doesn't reproduce problem. compiles cleanly on ubuntu 12.04 lts derivative gcc 4.9.0. assumes have header <err.h>
defines function err()
. i'm not destructor necessary mcve (and removing eliminate 5 lines or so).
#include <cstdio> #include <pthread.h> #include <unistd.h> #include <err.h> namespace gr { namespace adsb { class out_impl { public: out_impl(); virtual ~out_impl(); }; void *task_udprx(void *arg) { while (true) { printf("task udprx %p\n\r", arg); usleep(500*1000); } pthread_exit(null); } out_impl::out_impl() { pthread_t thread_udprx; if (pthread_create(&thread_udprx, null, task_udprx, null)) err(1, "pthread error"); else printf("udp thread initialization completed\n\r"); } out_impl::~out_impl() { } } }
compilation $ g++ --version g++ (gcc) 4.9.0 copyright (c) 2014 free software foundation, inc. free software; see source copying conditions. there no warranty; not merchantability or fitness particular purpose. $ create gr.o g++ -g -o3 -std=c++11 -wall -wextra -werror -c gr.cpp $ nm -c -g gr.o 0000000000000010 t gr::adsb::task_udprx(void*) 0000000000000050 t gr::adsb::out_impl::out_impl() 0000000000000050 t gr::adsb::out_impl::out_impl() 0000000000000040 t gr::adsb::out_impl::~out_impl() 0000000000000000 t gr::adsb::out_impl::~out_impl() 0000000000000000 t gr::adsb::out_impl::~out_impl() 0000000000000000 v typeinfo gr::adsb::out_impl 0000000000000000 v typeinfo name gr::adsb::out_impl u vtable __cxxabiv1::__class_type_info 0000000000000000 v vtable gr::adsb::out_impl u operator delete(void*) u err u printf u pthread_create u usleep $
next steps there several ways q&a can go here:
the question abandoned or closed. you take mcve code , add together stuff until original compilation error. you take non-compiling code , remove stuff until mcve can remove nil without removing error. preferably, code should not refer headers not found on regular linux installation. if must, need identify they're obtainable — yes, can find gnu radio if have to, shouldn't need so. c++ multithreading void gnuradio
Comments
Post a Comment