1834882 Members
2528 Online
110071 Solutions
New Discussion

ioctl with thread

 
Dboy_1
Occasional Contributor

ioctl with thread

i have a program that using ioctl(2) in a thread environment. i compiled it with -lpthread option and without error. but when i run it there are error like this:
"Invalid argument"
thrown by ioctl(2).

what maybe is the reason?
6 REPLIES 6
A. Clay Stephenson
Acclaimed Contributor

Re: ioctl with thread

The reason is that you are using ioctl() incorrectly whether or not you are using threads. Every ioctl() requires at least 2 integer arguments and generally a 3rd argument which is driver/request dependent. Because ioctl() is directly related to the underlying driver, it's not possible to help much more without knowing the context of the system call.
If it ain't broke, I can fix that.
Dboy_1
Occasional Contributor

Re: ioctl with thread

Thank you.
But i can run the program without multi-thread environment. so i think there are problems in multi-thread using ioctl.
And now i can compiled it with -lpthread option. But ioctl still return -1.
A. Clay Stephenson
Acclaimed Contributor

Re: ioctl with thread

I can absolutely assure that ioctl(2) has no meaning. The first argument is the file descriptor but w/o the remaining arguments whatever randomly happens to be in the registers or stack are used as the remaining arguments to ioctl.
If it ain't broke, I can fix that.
Dboy_1
Occasional Contributor

Re: ioctl with thread

excuse me, what's the meaning of the w/o?
Your meaning is there are some problems in my using the first argument of the ioctl?
i think there are maybe some problems with ioctl and pthread_mutex_lock?
the program like this:
for( ; ; ){
pthread_mutex_lock(&a);
while (event == NULL) {
pthread_cond_wai(&b,&a);
}
while (p != NULL) {
ã ã ã ioctl(fd, ...);
ã ã ã p = p->next;
ã ã }
pthread_cond_timedwait(&b,&a,&c);
pthread_mutex_unlock(&a);
}
A. Clay Stephenson
Acclaimed Contributor

Re: ioctl with thread

w/o = without. We are having language problems. When you said you were using ioctl(2), I took that literally in that you were calling ioctl with ONLY the first argument.

In your last posting, whatever is before ioctl(2,...) is garbled so I cannot comment on that.


If it ain't broke, I can fix that.
Dboy_1
Occasional Contributor

Re: ioctl with thread

Sorry. i'm meaning i use the ioctl system call.
for( ; ; ){
pthread_mutex_lock(&a);
while (event == NULL) {
pthread_cond_wai(&b,&a);
}
while (p != NULL) {
fd = socket(...);
ioctl(fd, ...);
close(fd);
p = p->next;
}
pthread_cond_timedwait(&b,&a,&c);
pthread_mutex_unlock(&a);
}

when i don't use the pthread_cond_timedwait(), there are no error.