Possible Duplicate:
Multiple arguments to function called by pthread_create()?
How to pass more than one value as an argument to a thread in C?
I have these structures:
struct Request {
char buf[MAXLENREQ];
char inf[MAXLENREQ]; /* buffer per richiesta INF */
int lenreq;
uint16_t port; /* porta server */
struct in_addr serveraddr; /* ip server sockaddr_in */
char path[MAXLENPATH];
/*struct Range range;*/
};
struct RequestGet {
char buf[MAXLENREQ];
int maxconnect;
struct Range range;
};
struct ResponseGet{
char buf[MAXLENDATA];
//int LenRange;
int expire;
char dati[MAXLENDATA];
struct Range range;
};
How can I pass them to pthread_create? No matter about the meanings of each field of structures.
pthread_create(&id,NULL,thread_func,????HERE????);
You can only pass one parameter, so you generally need to make a function that takes one parameter, even if it just wraps some other calls. You can do this by creating a
structand having the function take a pointer to such astruct.A basic example to illustrate the point is below. Please note that it is not a complete example, and should not be used as-is! Note, for example, that none of the memory allocated with
malloc()is freed.