Date: Wed, 15 May 2013 23:18:51 +0200 From: Jilles Tjoelker <jilles@stack.nl> To: Radio =?utf-8?B?bcWCb2R5Y2ggYmFuZHl0w7N3?= <radiomlodychbandytow@o2.pl> Cc: freebsd-threads@freebsd.org Subject: Re: Getting ENOMEM with pthread_mutex_init Message-ID: <20130515211851.GA29110@stack.nl> In-Reply-To: <5184F113.805@o2.pl> References: <5184F113.805@o2.pl>
next in thread | previous in thread | raw e-mail | index | archive | help
On Sat, May 04, 2013 at 01:29:23PM +0200, Radio młodych bandytów wrote: > 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? It is probably not the cause of your problem but using a copy of a pthread_mutex_t for synchronization is not allowed. pthread_mutex_init() should be called on the pthread_mutex_t that is part of the Scheduler. -- Jilles Tjoelker
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20130515211851.GA29110>