From owner-freebsd-threads@FreeBSD.ORG Fri May 17 18:47:41 2013 Return-Path: Delivered-To: freebsd-threads@freebsd.org Received: from mx1.freebsd.org (mx1.FreeBSD.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id 0D00B722 for ; Fri, 17 May 2013 18:47:41 +0000 (UTC) (envelope-from radiomlodychbandytow@o2.pl) Received: from moh3-ve3.go2.pl (moh3-ve3.go2.pl [193.17.41.87]) by mx1.freebsd.org (Postfix) with ESMTP id C5D98F88 for ; Fri, 17 May 2013 18:47:40 +0000 (UTC) Received: from moh3-ve3.go2.pl (unknown [10.0.0.158]) by moh3-ve3.go2.pl (Postfix) with ESMTP id 7266DB5A71F for ; Fri, 17 May 2013 20:47:29 +0200 (CEST) Received: from unknown (unknown [10.0.0.74]) by moh3-ve3.go2.pl (Postfix) with SMTP for ; Fri, 17 May 2013 20:47:29 +0200 (CEST) Received: from unknown [93.175.66.185] by poczta.o2.pl with ESMTP id ESrzpU; Fri, 17 May 2013 20:47:29 +0200 Message-ID: <51967B40.9060409@o2.pl> Date: Fri, 17 May 2013 20:47:28 +0200 From: =?UTF-8?B?UmFkaW8gbcWCb2R5Y2ggYmFuZHl0w7N3?= User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:17.0) Gecko/20130407 Thunderbird/17.0.5 MIME-Version: 1.0 To: Jilles Tjoelker Subject: Re: Getting ENOMEM with pthread_mutex_init References: <5184F113.805@o2.pl> <20130515211851.GA29110@stack.nl> In-Reply-To: <20130515211851.GA29110@stack.nl> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-O2-Trust: 1, 37 X-O2-SPF: neutral Cc: freebsd-threads@freebsd.org X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 17 May 2013 18:47:41 -0000 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