Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 04 May 2013 13:29:23 +0200
From:      =?UTF-8?B?UmFkaW8gbcWCb2R5Y2ggYmFuZHl0w7N3?= <radiomlodychbandytow@o2.pl>
To:        freebsd-threads@freebsd.org
Subject:   Getting ENOMEM with pthread_mutex_init
Message-ID:  <5184F113.805@o2.pl>

Next in thread | Raw E-Mail | Index | Archive | Help
Hello,
I'm having troubles that I seem unable to resolve.
My programs creates and destroys mutexes repeatably (and, obviously,
uses them in between). Around the 60th lock created, I always get ENOMEM.
I have free memory, lots of it. All locks get released properly.

The relevant pieces of code:

#define MUTEX pthread_mutex_t
inline MUTEX create_mutex()
{
    MUTEX mutex;
    int ret = pthread_mutex_init(&mutex, NULL);
    if(ret != 0)
        throw std::runtime_error("Failed to create a mutex");
    return mutex;
}

inline void destroy_mutex(MUTEX *mutex)
{
    int ret = pthread_mutex_destroy(mutex);
    if(ret != 0)
        throw std::runtime_error("Failed to destroy a mutex");
}

Scheduler::Scheduler(char* in,
                     char* out,
                     BlockInfo* metadata,
                     size_t isize,
                     size_t block_size,
                     size_t iters,
                     size_t min_work_size) :
        in(in),
        current_in(in),
        out(out),
        current_out(out),
        metadata(metadata),
        current_metadata(metadata),
        size(isize),
        size_left(isize),
        block_size(block_size),
        iters_left(iters)
{
    lock = create_mutex();
    work_size = (min_work_size / block_size) * block_size;
    if (work_size < min_work_size)
        work_size += block_size;
}
Scheduler::~Scheduler()
{
    destroy_mutex(&lock);
}

Any suggestions?

-- 
Twoje radio




Want to link to this message? Use this URL: <http://docs.FreeBSD.org/cgi/mid.cgi?5184F113.805>