c - pthread, linked list with a double pointer -


i have got far create accurate consumer-producer type model test application making last bit causing me problems.

i have 2 structs set-up application. 1 used linked list used list of work has done. other 1 struct specific each thread contains double pointer linked list. don`t use single pointer unable modify pointer in 1 thread , detect change in other.

//linked list struct:  typedef struct list_of_work list_of_work; struct list_of_work {     // information work       list_of_work        *next;  };  //thread struct:  typedef struct thread_specs {      list_of_work         **linked_list;      unsigned short       thread_id;      pthread_mutex_t      *linked_list_mtx;  } thread_specs; 

the double pointer in thread_specs bound double pointer of root of list_of_work struct so:

in main:

list_of_work                         *root; list_of_work                         *traveller; pthread_t                            thread1; thread_specs                         thread1_info;  // allocating root , other stuff traveller = root; thread1_info.linked_list = &traveller; 

this works without warnings or errors.

now go on create pthread with:

pthread_create(&thread1, null, worker, &thread1_info ) 

and in pthread perform 2 casts, 1 cast thread_info struct , other cast linked list. ptr argument:

thread_specs            *thread = (thread_specs *)ptr; list_of_work            *work_list = (list_of_work *)thread->linked_list; list_of_work            *temp; 

this throws no errors.

i have function called list_of_work *get_work(list_of_work *ptr), function works won't post entire thing can see expects see pointer linked list , returns pointer of same linked list(which either null or next piece of work).

so use function next piece of work this:

temp = get_work(*work_list); if (temp != null) {     work_list = &temp;     printf("thread: %d || found work, printing type of work.... ",thread->thread_id); } 

now crux. how can correctly cast , pass pointer behind first pointer get_work() function can does.

my compiler spits warnings:

recode.c:348:9: error: incompatible type argument 1 of ‘get_work’ recode.c:169:14: note: expected ‘struct list_of_work *’ argument of type ‘list_of_work’ 

i thank whoever can hep me!

based on function get_work()'s definition posted , error message, issue here:

temp = get_work(work_list);                 ^    /* notice there's no dereferencing here */ 

the function expects pointer struct list_of_work whereas pass struct list_of_work.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -