tags:

views:

152

answers:

1

Hi StackOverflow,

Can someone tell me the correct way of passing multiple vectors to a function that can take only a single argument? (specifically for pthread_create (..) function)

I tried the following but it does not seem to work :-(

First, I created the following structure

struct ip2

{

    void* obj;
    int dim;
    int n_s;
    vector<vector<vector<double> > > *wlist;
    vector<int> *nrsv;
    struct model *pModel;

};

The threads that I have created actually needs all these parameters. Since im using pthreads_create I put all this in a structure and then passed the pointer to the structure as an argument to pthread_create (as shown).

some_fxn()

{

    //some code

    struct ip2 ip;

    ip.obj=(void*) this;

    ip.n_s=n_s;

    ip.wlist=&wlist;

    ip.nrsv=&nrsv;

    ip.pModel=pModel;

    ip.dim=dim;

    pthread_create(&callThd1[lcntr], &attr1, &Cls::Entry, (void*) &ip);

}

The Entry method looks something like this.

void* Cls::Entry(void *ip)

{

    struct ip2 *x;
    x = (struct ip2 *)ip;
    (reinterpret_cast<Cls1 *>(x->obj))->Run(x->dim,x->n_s, x->wlist, x->nrsv, x->pModel);


}

The Run method looks something like this.

void Run(int dim, int n_c, vector<vector<vector<double> > > *wlist, vector<int> *nrsv, struct model* pModel )

{

    //some code
        for(int k = 0; k < n_c; ++k)
    {
        //some code

    end = index + nrsv[k];

    //some code

}

I get the following error when I try to compile the program.

error: no match for ‘operator+’ in ‘index + *(((std::vector<int, std::allocator<int> >*)(((unsigned int)k) * 12u)) + nrsv)’

Can someone tell me how to do it the right way.

Madhavan

A: 

nrsv is a vector<int>*, right? So you need to do end = index + (*nrsv)[k]; (dereference it).

crimson_penguin
Note: I didn't really look over the actual code much, I was just looking at the particular compile error you reported.
crimson_penguin
yes it works.. i forgot to dereference it! Thanks!
madman
No problem! You should really listen to those other people's comments too though. Particularly Tuomas.
crimson_penguin