data1->transformed_block[l] = &transformed_block[l];
-
void print_message_function ( void *ptr )
{
dt *data;
data = (dt *) ptr;
printf("Dentro da thread Numero0: %ld\n", data->L_norm_NewBlock);
pthread_exit(0);
}
typedef struct data_thread
{
long L_norm_NewBlock;
int Bsize_X;
int Bsize_Y;
int *transformed_block[MAX_LEVEL];
long L_norm_OrigBlock;
} dt;
void function()
{
int *transformed_block[MAX_LEVEL];
pthread_t thread1;
dt *data1;
pthread_attr_t attr;
pthread_attr_init(&attr);
//Fills structure
data1 = (dt *) malloc(sizeof(dt));
data1->transformed_block[l] = &transformed_block[l];
data1->L_norm_NewBlock=0;
data1->Bsize_Y = Bsize_Y;
data1->Bsize_X = Bsize_X;
pthread_create(&thread1, &attr, (void *) &print_message_function, (void *) &data1);
}
I want to get rid of that warning, and the values i get inside the thread are wrong. For example data1->L_norm_NewBlock=0; in the thread guives me a differente value (not 0 like it should be).
What is transformed_block ? Assuming that it is the same as the variable defined in the struct, you are trying to assign the address of the lth element (pointer to an int pointer) to the lth element of the data1->transformed_block (a pointer to an int).
data1->transformed_block[l] = &transformed_block[l];
// int* = &(int*)
Aren't you trying to simply assing?
data1->transformed_block[l] = transformed_block[l];
You have an array of int pointers in your structure and declared as a local variable in your function, however you never assign it to point to anything.
If you are trying to have a local array in function() you should declare int transform_block[MAX_LEVEL], rather than int* transform_block[MAX_LEVEL]. That should make the warning go away.
void function()
{
int transformed_block[MAX_LEVEL]; pthread_t thread1;
// * removed from above line
dt *data1;
...
The values inside the thread are okay now. I erased the & in the function
pthread_create(&thread1, &attr, (void *) &print_message_function, (void *) &data1);
to
pthread_create(&thread1, &attr, (void *) &print_message_function, (void *) data1);
But I still haven't got rid of that warning...
精彩评论