On Fri, 19 Oct 2007 23:40:54 +0100, Peter Pichler
<usenet@pichler.co.uk> wrote:
> Mahendra Kumar Kutare wrote:
> > void *accept_requests(void *params) {
> >
> > int socket_fd = (int) params;
>
> Casting a pointer to int is usually a Bad Idea [tm]. You are not using
> params anywhere else in your accept_requests(), so why not making the
> argument int?
> Your accept_requests() is declared as returning void*, but there is no
> return statement. If you ever use the return value, you are asking for
> trouble. Either return a valid void* or declare the function as void.
#if offtopic == threading
The OP's code was obviously designed to run under POSIX threads aka
pthreads, and that requires that a thread-function takes one void* and
returns void*. If you want to pass anything else you either store it
(uniquely) in memory and pass a pointer, or nonportably cast your
small-enough data to void* and back as here. It should return some
valid value UNLESS you (always) pthread_exit instead as he does,
although if no other code/thread uses pthread_join to get that return
value it doesn't matter what it is.
#endif
#if boilerplate
To the OP, and anyone else in a similar situation: if you have
questions about or problems with the multithreading issues involved in
a program like this, they are offtopic in comp.lang.c because Standard
C does not define or require any kind of threading, pthread or other.
Go to comp.programming.threads instead.
Issues of C structure, practice, or style are ontopic here, but you
should either omit the threading-related and therefore offtopic parts,
or if you can't omit them (e.g. if the question is about them) clearly
identify and acknowledge their nonstandardness to avoid flamage.
And it's a good idea to check the FrequentlyAskedQuestions-list first,
at the usual places and
http://c-faq.com -- re-asking a FAQ is
considered rude. If you don't understand or aren't satisfied with the
FAQ-answer, explain that specifically. Good luck.
#endif
- formerly david.thompson1 || achar(64) || worldnet.att.net