multithreading - deleting data sent to thread in FLTK using c++ -


i'm performing long task, implemented in function, in new thread (i.e. not main gui thread) in fltk (in c++).

i achieve callback function in turn creates thread have of form

void callback(fl_widget* widget,void* passed_data){  data_type* data = new data_type;  data->value = x; //populate data structure send function  fl_create_thread(thread1,function,data);  } 

where fl_create_thread (at least purposes) using pthread_create meaning data variable passed void pointer , 'function' takes void pointer too.

i realised create memory leak don't delete 'data': can't delete after line fl_create_thread thread hasn't (or ever) finished running. have tried deleting pointer @ end of 'function' raises 2 issues

1) deleting void pointer undefined , getting warnings effect.

2) defeats point of using function: there better general coding practice?

can tell me how should approach this? thanks.

1) deleting void pointer undefined , getting warnings effect.

you're casting proper type @ beginning of function (or should in order meaningfully use parameter). delete pointer instead of void * parameter , not warning.

2) defeats point of using function: there better general coding practice?

not sure see point. thread interface (pthread) c-like, has resort void pointers in order pass arbitrary data. can @ c++ thread interface more c++ way of defining execute , parameters

with memory should have clear ownership of allocated memory. approach transfers ownership created thread.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -