[Q]pthread_mutex_init() occurs error, ENOMEM

"Seungjun Lee" <[email protected]> Thu, 31 Oct 2002 23:45:30 -0500
Newsgroups gmane.linux.ngpt.user
Message-ID <[email protected]>
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