Readon Shaw wrote:
> I am using select in two thread, one get fd with 0, the other
> is 14. when i select() them, it would return -1 and the error reported
> that "bad file descriptor". does select a thread safe function?
> ps: when the fd is 14 and 15, the system works well.
If 'select' returns -1 and the error is "bad file descriptor", that
means you have a bug in your code that cause you to call 'select' with
an fd set that is bad in some way.
Yes, 'select' is a thread safe function.
It's hard to tell what your problem is from such a vague description,
but one possibility might be that somewhere in your code, you close
file descriptor zero (or are invoked without one). Then your code just
assumes that there must be a valid 'stdin', so 'select's on it. This
will return "bad file descriptor" if no files have been opened. It can
do much worse things if one has.
DS
|