I am creating a data-parallel program using pthreads and C++. From http://stackoverflow.com/questions/1151582/pthread-function-from-a-class, I found out how to supply pthread_create
with a function pointer to a static C++ function(and supply it a this
argument).
However, I also need to supply the thread with an index, so it knows what data it's working on. I could malloc
a struct for each thread(with both the pointer to the C++ class and an index), but this seems like it would add some bookkeeping code, and could lead to leaks if the struct isn't freed. Is there a better way to do this?