开发者

Passing multiple arguments to a thread from a structure

I'm having problems passing the arguments, using a structure containing another structure

i know there's something wrong with the way i'm using the structures but i just cant see where...

Thanks!

this is my struct

typedef struct {
IMAGE *imagenfte;
IMAGE *imagendst;
}thread_data;

//thread_data *data = (thread_data *) malloc(sizeof(thread_data));

this is the other structure

 typedef struct {
    HEADER header;
    INFOHEADER infoheader;
    PIXEL *pixel;
    } IMAGE;

IMAGE imagenfte,imagendst;

this is my thread function

void *processBMP2(void *argumentos) 
{
thread_data *my_data;
my_data =  (thread_data *) (argumentos);
IMAGE *imagefte, *imagedst;
imagefte =  my_data->imagenfte;
imagedst = my_data->imagendst;
free(my_data);
int i,j;
int count=0;
PIXEL *pfte,*pdst;
PIXEL *v0,*v1,*v2,*v3,*v4,*v5,*v6,*v7;
int imageRows,imageCols;
memcpy(imagedst,imagefte,sizeof(IMAGE)-sizeof(PIXEL *));
imageRows = imagefte->infoheader.rows;
imageCols = imagefte->infoheader.cols;
imagedst->pixel=(PIXEL *)malloc(sizeof(PIXEL)*imageRows*imageCols);
...

and this is the way i`m creating the thread and passing de arguments

     pthread_t hilo;

thread_data *my_data = (thread_data *) malloc(sizeof(thread_dat开发者_开发知识库a));

my_data->imagenfte = &imagenfte;
my_data->imagendst = &imagendst;

pthread_create(&hilo,NULL, processBMP2, my_data);

//processBMP(&imagenfte,&imagendst);


What you're doing is exactly right. The new thread needs to be the one responsible for freeing the memory because the parent thread cannot know when the new thread is done accessing it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜