pthreads

This is a discussion on pthreads within the C Programming forums, part of the General Programming Boards category; I have a question about the pthread_create function. A normal use of that function would be something like this. Code: ...

  1. #1
    Registered User
    Join Date
    Apr 2005
    Posts
    67

    pthreads

    I have a question about the pthread_create function.
    A normal use of that function would be something like this.
    Code:
       int itr =pthread_create(&my_thread,NULL, void *(*start_routine)(void*), void *arg);
    Can I use the function diferently? Do I always have to have a pointer to my function that the thread will execute and what does (void*) after (*start_routine) mean?

    How could I use the function that takes no arguments, it's just a simple void..Let's say I have two void function's that print out 2 different words, how can I now make 2 threads ,each using one of those two functions?

  2. #2
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,048
    what does (void*) after (*start_routine) mean?
    It takes a pointer to a function that takes (void*) as its parameter list. Wait a minute . . . a pointer to a pointer to a function with a void* as a parameter.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  3. #3
    Registered User
    Join Date
    Apr 2005
    Posts
    67
    THere are times when I ask myself: "Why the ........ is C built that way??!!!"
    IM kidding...

    Thanks for explaining...so the thing in braces is just telling the function what type the parameter is.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. using pthreads with an API that uses pthreads
    By MK27 in forum C Programming
    Replies: 3
    Last Post: 03-06-2009, 02:47 PM
  2. Pthreads performance
    By C_ntua in forum C Programming
    Replies: 42
    Last Post: 06-17-2008, 12:29 PM
  3. Replies: 3
    Last Post: 04-16-2007, 01:02 PM
  4. Difference between win32 and linux pthreads
    By philipsan in forum C Programming
    Replies: 1
    Last Post: 02-07-2006, 04:57 PM
  5. pthreads and resources
    By ubermensch in forum C Programming
    Replies: 2
    Last Post: 02-07-2006, 02:27 AM

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