Pthread question, multiple arguments

This is a discussion on Pthread question, multiple arguments within the C Programming forums, part of the General Programming Boards category; Hi, i have a thread where i add my function to it. But the problem is i have 3 function ...

  1. #1
    Registered User
    Join Date
    Jan 2012
    Posts
    25

    Pthread question, multiple arguments

    Hi,

    i have a thread where i add my function to it. But the problem is i have 3 function more which they have to be added also to the same thread.

    Fore example:
    Code:
    rv = pthread_create (&tarray[i], NULL, (void *)&function1, (void *)&var;
    My question is how do i add muliple arguments in pthread_create?

  2. #2
    cas
    cas is offline
    Registered User
    Join Date
    Sep 2007
    Posts
    993
    You don't. If you need them running concurrently, call pthread_create() 3 times.

    You should also drop the casts. The casting of a function pointer to void* is simply wrong (the type expected is void*(*), not void*); the casting of an object pointer to void* in C is not necessary because it happens automatically. There is an advantage to leaving off casts, too: it allows the compiler to tell you if you're using the wrong type in a lot of cases.

  3. #3
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,657
    If I'm understanding you correctly, then just call the other functions within function1().

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. help with pthread and multiple arguments
    By user_name_void in forum C Programming
    Replies: 4
    Last Post: 02-17-2010, 03:23 PM
  2. Multiple command line arguments with switches
    By Ene Dene in forum C++ Programming
    Replies: 4
    Last Post: 02-27-2009, 03:28 AM
  3. Sending multiple arguments to function..
    By Zzaacchh in forum C++ Programming
    Replies: 3
    Last Post: 09-06-2008, 04:20 PM
  4. pthread and multiple CPU
    By noelloen in forum C Programming
    Replies: 4
    Last Post: 03-07-2006, 12:00 PM
  5. multiple command line arguments
    By christee in forum C Programming
    Replies: 4
    Last Post: 04-08-2003, 09:35 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21