0

I am creating thread using pthread_create and in its handler I need to pass more than one argument.

Is it possible to pass multiple arguments, and if yes then how?

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
  • Have a look at http://stackoverflow.com/questions/1352749/multiple-arguments-to-function-called-by-pthread-create, could be a duplicate – joe_young Jun 21 '15 at 07:21
  • @joe_young yes I have seen . but they are passing structure and using that structure address accessing both arguments and in my case I want to pass to different structures which are not related with each other in any sense. – Ayush Agarwal Jun 21 '15 at 07:30
  • 1
    @AyushAgarwal you could use a structure holding pointers to the actual structures you need. There is no was of passing more than one void* parameter to pthread_create. – Ishay Peled Jun 21 '15 at 07:34
  • You need to show what you mean, but the short answer is "You can't; you have to pass a single pointer to void to the thread function, and that pointer must point to all the relevant information, and the standard, orthodox way of passing multiple values is by creating a structure to hold the multiple values and passing a pointer to such a structure to the thread function", or words to that effect. – Jonathan Leffler Jun 21 '15 at 07:34
  • Yeah, essentially, if you can pass in one pointer, you can pass in anything. – Martin James Jun 21 '15 at 07:40
  • ok.. thanks i will try – Ayush Agarwal Jun 21 '15 at 08:07

0 Answers0