Date: Fri, 17 May 2013 20:47:28 +0200 From: =?UTF-8?B?UmFkaW8gbcWCb2R5Y2ggYmFuZHl0w7N3?= <radiomlodychbandytow@o2.pl> To: Jilles Tjoelker <jilles@stack.nl> Cc: freebsd-threads@freebsd.org Subject: Re: Getting ENOMEM with pthread_mutex_init Message-ID: <51967B40.9060409@o2.pl> In-Reply-To: <20130515211851.GA29110@stack.nl> References: <5184F113.805@o2.pl> <20130515211851.GA29110@stack.nl>
next in thread | previous in thread | raw e-mail | index | archive | help
On 15/05/2013 23:18, Jilles Tjoelker wrote: > 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. > Thanks for the suggestion. I just tried it and it didn't help though... -- Twoje radio
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?51967B40.9060409>