Click to See Complete Forum and Search --> : pthread_create returns -1?
malletelf
February 12th, 2003, 03:10 AM
Hi all.
Anyone had any trouble with pthread_create returning -1? I'm not sure what to do about it, so any and all suggestions would be appreciated!
Thanks in advance!
// Code:
/////////////////////////////////////////////////////////////////
coid *Client(coid *);
void main(){
......
pthread_t clientid[MAXCLIENTS] /* MAXCLIENTS == 32 */
pthread_attr_init(&attr);
pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM);
......
for ( ; ; ){
......
pthread_create(&clientid[i], &attr, Client, (void *) i);
......
}
}
dimm_coder
February 12th, 2003, 03:55 AM
Is it a real code? But here U dont check for pthread_create return code.
for(;; ) ???
Did U try to create only 32 as declared above?
Possible error for pthread_create is only EAGAIN, which means no more system resources available,
ofcourse if U write for(;; ) and try to create unbounded count of threads.
malletelf
February 12th, 2003, 04:08 AM
Attached is the entire server code.
I will add checking to make sure I only allow 32 clients.
http://www.opengroup.org/onlinepubs/007908799/xsh/pthread_create.html
ERRORS
The pthread_create() function will fail if:
[EAGAIN]
The system lacked the necessary resources to create another thread, or the system-imposed limit on the total number of threads in a process PTHREAD_THREADS_MAX would be exceeded.
[EINVAL]
The value specified by attr is invalid.
[EPERM]
The caller does not have appropriate permission to set the required scheduling parameters or scheduling policy.
The pthread_create() function will not return an error code of [EINTR].
dimm_coder
February 12th, 2003, 04:15 AM
It returns -1 on the 1-st step of iteration?
Look system errno variable for error code.
malletelf
February 12th, 2003, 04:40 AM
Yes, it returns -1 on the first iteration.
perror/errno return an error code of 0.
Were you able to see my attached files? That was the first time I've tried and I wasn't sure how it worked.
dimm_coder
February 12th, 2003, 05:35 AM
Strange that 0 :confused:
That means no error.
Are U try setscope for return code?
malletelf
February 12th, 2003, 06:28 AM
I tried setscope, and everything else dealing with the thread. All variables are correct and all parameters seem to be correct.
I have class shortly, I can ask the professor. Hopefully he can shed some light on it, but I'm not so sure.
As this assignment is due in 15 1/2 hours, and there's plenty left to do, don't be surprised to see more posts here, lol.
dimm_coder
February 12th, 2003, 06:38 AM
U can attach here your sources if it will be possible for U. May be it will give some light.
malletelf
February 12th, 2003, 07:02 AM
Hopefully these clear things up a little.
Thanks for all your help!!
dimm_coder
February 12th, 2003, 07:53 AM
I compiled your server, run it, then with telnet opened a connection. So all was OK! No any error with pthread_create(). perror gave "Invalid seek" for pthread_attr_setscope(). Why do U use it? This default value for posix linux threads, as I remember, or U use another UNIX?
So for some time it works until telnet breaked it. I put printf() into Client() - function and it worked.
So I hadn't error with pthread_create().
malletelf
February 12th, 2003, 08:10 AM
I'm working from a Sparc server running SunOS 5.8.
I'll have to say it is the computers that make the difference, because even doing what you did, I can't make it work.
Sometimes if feels as though I'm beating a dead horse with the network programming we've been doing.
malletelf
February 12th, 2003, 08:32 AM
Well, what can I say?
I'm terribly sorry to have wasted your time on this.
Turns out that I didn't include the proper compiler directives in my make file.
I guess that's why I'm a student though.
Thanks again.
dimm_coder
February 12th, 2003, 08:33 AM
I didn't work with Spark platform and SunOS. This is very simple sample U 've provided. And quike view didn't recognise any problems with network part. Of course, it has it, but they cannot make problem U have.
So I don't know, may be it depends of Sun posix realization or something else.
Did U try this without pthread_attr_setscope()?
Else why fork()? U create a child process, then create thread in it, but then after a little a child process is ended and thread U created too.
It is enough to call pthread_create() to create a client thread.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.