Writing a callback function in linux and max using pthreads

As mentioned in my previous post, we do the same thing but we do it using pthreads.
we can do this in two ways. suppose your writing this code for yourself, and its not going to be distributed, meaning you really dont care about version of pthreads while linking, you can directly define pthreads.
pthread_create( &thread_id[i], NULL, thread_function, NULL );
But if its something you are bothered about the versions, you need to use a typedef for this as below:
#include <pthread.h> //this is in the header file
typedef int (*ForCallback)(pthread_t *, const pthread_attr_t *,
void *(*)(void *), void *);
//put this in the source
pthread_t             thread;
instanceOfForCallback(&thread, NULL, OESIS_Callback_helper,objOesisCallback);
ForCallback(&thread, NULL, OESIS_Callback_helper,objOesisCallback);
Now with the above you can run new methods. the other issues remain the same.
Some things you need to be sure are:
dont use system() command, unless you give proper critical sections and so on.

In

Leave a Reply

Your email address will not be published. Required fields are marked *