Re: [Q]pthread_mutex_init() occurs error, ENOMEM

"Saurabh Desai" <[email protected]> Tue, 5 Nov 2002 13:04:31 -0600
Newsgroups gmane.linux.ngpt.user
Message-ID <[email protected]>

---------------------- Forwarded by Saurabh Desai/Austin/IBM on 11/05/2002
01:04 PM ---------------------------

Saurabh Desai
11/04/2002 04:38 PM

To:    "Seungjun Lee" <[email protected]>
cc:
From:  Saurabh Desai/Austin/IBM@IBMUS
Subject:    Re: [pthreads-users] [Q]pthread_mutex_init() occurs error,
       ENOMEM  (Document link: Saurabh Desai)


You don't need to define the _PTHREAD_PRIVATE. It's used for library
specific internal purpose only. The pthread_mutex_st structure in both
the header files are of same size and should be fine. The NGPT allocates
memory for mutexes. I tried your test program and it works for me.
Did you see the ENOMEM error at very first run of this program?
During initialization. it allocates shared-area for shared-mutexes and
later
use it during mutex initialization. Can you run the /usr/bin/ngptc and
tried
this program again? Only time the pthread_mutex_init() returns ENOMEM
for shared-mutexes is when all the 256 internal mutexes are in use.

Thanks,
- - - - -
Saurabh Desai
POSIX Threading for Linux
IBM  Linux Technology Center
e-mail: [email protected] OR [email protected]
phone: 512-838-2655, T/L: 678-2655




"Seungjun Lee" <[email protected]>@www-124.southbury.usf.ibm.com on 10/31/2002
10:45:30 PM

Sent by:    [email protected]


To:    [email protected]
cc:
Subject:    [pthreads-users] [Q]pthread_mutex_init() occurs error, ENOMEM


Hi!

I wrote a simple code to test

"pthread_mutexattr_setpshared()" function, LinuxThread was not
implemented..

with kernel 2.5.25, gcc 2.96, ngpt-2.0.3

I have two questions... First one is ..
-----------------------------------------------
#define _PTHREAD_PRIVATE
#include <pthread.h>
#include <string.h>
#include <errno.h>

int
main(void) {
    pthread_mutex_t mutex;

    if (Mutex_init(&mutex) != 1) {
        printf("Error:Mutex_init() \n");
        exit(1);
    }
    if ( Mutex_destroy(&mutex) == 0) {
        printf("Error:Mutex_destroy() \n");
        exit(1);
    }
}

int
Mutex_init(pthread_mutex_t *mp) {
    pthread_mutex_t tmp = PTHREAD_MUTEX_INITIALIZER;
    pthread_mutexattr_t mattr;

    memcpy(mp, &tmp, sizeof(pthread_mutex_t));

        if (pthread_mutexattr_init(&mattr) != 0) {
            perror("pthread_mutexattr_init");
            exit(1);
        }

        if (pthread_mutexattr_setpshared(&mattr, PTHREAD_PROCESS_SHARED) !
= 0) {
            perror("pthread_mutexattr_setpshared");
            exit(1);
        }

        // error occurs in here..
        // pthread_mutex_init() returns "12" error number, or ENOMEM
        if ((rc = pthread_mutex_init(mp, (const pthread_mutexattr_t *)
&mattr)) != 0 ) {
            perror("[Error!]pthread_mutex_init");
            exit(1);
        }

        if (pthread_mutexattr_destroy(&mattr) != 0) {
            perror("pthread_mutexattr_destroy");
            exit(1);
        }

        return 1;
}

int
Mutex_destroy(pthread_mutex_t *mp) {
    if ( pthread_mutex_destroy(mp) == 0) {
        printf("Success....\n");
        return 1;
    } else {
        printf("Error!!!! \n");
        return 0;
    }
}
------------------------------------------------

if I run this code,
pthread_mutex_init() returns error number, 12(ENOMEM)

I don't know what I wrong...

===
Second one is ..

If I don't write "#define _PTHREAD_PRIVATE" (first line the code I wrote)
"pthread_mutex_t" refers "pthread_mutex_t" in
ngpt/include/bits/pthreadtypes.h...
or,

struct pthread_mutex_st {
    void *  res0;
    int     res1;
    int     res2;
    int     res3;
    int     res4;
    int     res5;
};
typedef struct  pthread_mutex_st         pthread_mutex_t;

not in ngpt/include/pthread.h...
or,
struct pthread_mutex_st {
    void *  mx_mutex;
    int     mx_init;
    int     res2;
    int     mx_kind;
    int     res3;
    int     mx_init_lock;
};
typedef struct  pthread_mutex_st         pthread_mutex_t;


Will I have to write the "#define _PTHREAD_PRIVATE" ?
Sometimes, it makes declaration/definition confliction with standard
library headers(at /usr/include)..


Thanks in advance..
--
__________________________________________________________
Sign-up for your own FREE Personalized E-mail at Mail.com
http://www.mail.com/?sr=signup

_______________________________________________
pthreads-users mailing list
[email protected]
http://www-124.ibm.com/developerworks/oss/mailman/listinfo/pthreads-users