Why does pthread_create fail?
I am trying to create a thread and getting an error value that doesn't
match the documentation.
Using the following code:
static pthread_t readThreadid = 0;
int pthread_createStatus;
int prevErrno;
if (readThreadid == 0)
{
prevErrno = errno;
pthread_createStatus
= pthread_create(&readThreadid, NULL, jsReadThread, NULL);
if (pthread_createStatus != 0)
{
printf("pthread_create failed, "
"status = %d, errno = %d, prevErrno = %d\n "
"(options are ENOMEM=%d, EINVAL=%d, EPERM=%d)\n\n\n\n",
pthread_createStatus, errno, prevErrno,
ENOMEM,EINVAL,EPERM);
I get the following output:
pthread_create failed, status = -1, errno = 234881046, prevErrno =
234881046
(options are ENOMEM=12, EINVAL=22, EPERM=1)
which tells me that:
pthread_createStatus returns a -1
errno does not change
The man page says:
If successful, the pthread_create() function returns 0.
Otherwise, an error number is returned to indicate the
error.
The pthread_create() function will fail if:
ENOMEM
EINVAL
EPERM
Therefore, I must have an error which does not set errno. How can I
determine what error I am getting?
Thanks.
Scott
[email]s.klein@ngc.com[/email]
Re: Why does pthread_create fail?
"s.klein@ngc.com" <s.klein@ngc.com> writes:
[color=blue]
>Therefore, I must have an error which does not set errno. How can I
>determine what error I am getting?[/color]
If the error is -1, then you've failed to link with libthread/libpthread.
Casper
--
Expressed in this posting are my opinions. They are in no way related
to opinions held by my employer, Sun Microsystems.
Statements on Sun products included here are not gospel and may
be fiction rather than truth.
Re: Why does pthread_create fail?
In article <1143752818.237944.279540@e56g2000cwe.googlegroups.com>,
[email]s.klein@ngc.com[/email] <s.klein@ngc.com> wrote:[color=blue]
>I am trying to create a thread and getting an error value that doesn't
>match the documentation.
>
>Using the following code:
>
> static pthread_t readThreadid = 0;
> int pthread_createStatus;
> int prevErrno;
> if (readThreadid == 0)
> {
> prevErrno = errno;
> pthread_createStatus
> = pthread_create(&readThreadid, NULL, jsReadThread, NULL);
> if (pthread_createStatus != 0)
> {
> printf("pthread_create failed, "
> "status = %d, errno = %d, prevErrno = %d\n "
> "(options are ENOMEM=%d, EINVAL=%d, EPERM=%d)\n\n\n\n",
> pthread_createStatus, errno, prevErrno,
> ENOMEM,EINVAL,EPERM);
>
>
>
>I get the following output:
>pthread_create failed, status = -1, errno = 234881046, prevErrno =
>234881046
>(options are ENOMEM=12, EINVAL=22, EPERM=1)
>
>which tells me that:
>pthread_createStatus returns a -1
>errno does not change
>
>The man page says:
>If successful, the pthread_create() function returns 0.
>Otherwise, an error number is returned to indicate the
>error.
>The pthread_create() function will fail if:
>ENOMEM
>EINVAL
>EPERM
>Therefore, I must have an error which does not set errno. How can I
>determine what error I am getting?[/color]
first, the manpage does *NOT* say that the global 'errno' is set.
It says that the FUNCTION RETURNS an error number on failure.
Thus _all_ the 'errno' stuff you're doing is irrelevant.
Secondly, as Caspar suggested, what libraries did you link with?