From mboxrd@z Thu Jan 1 00:00:00 1970 From: Ingo Molnar Subject: Re: [PATCH] kvm tools: Fix pthread mutex error checks Date: Sat, 9 Apr 2011 15:15:47 +0200 Message-ID: <20110409131547.GA12997@elte.hu> References: <1302350278-5478-1-git-send-email-penberg@kernel.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: kvm@vger.kernel.org, Asias He , Cyrill Gorcunov To: Pekka Enberg Return-path: Received: from mx3.mail.elte.hu ([157.181.1.138]:40818 "EHLO mx3.mail.elte.hu" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752176Ab1DINPw (ORCPT ); Sat, 9 Apr 2011 09:15:52 -0400 Content-Disposition: inline In-Reply-To: <1302350278-5478-1-git-send-email-penberg@kernel.org> Sender: kvm-owner@vger.kernel.org List-ID: * Pekka Enberg wrote: > The pthread_mutex_{lock|unlock} functions return non-zero, not negative number > upon error. Fix that wrong assumption in the code. glibc/pthreads mutex API semantics are pretty silly IMO. I *think* it would be better to try to match the kernel API here, and provide trivial wrappers around mutex_lock()/mutex_unlock(). We wont ever bring down threads in a hostile way, so we wont actually need the error returns. CPU threads should probably only exit once the kvm process exits, after all cleanup has been done. So mutex_lock() could be implemented as something like: void mutex_lock(pthread_mutex_t mutex) { if (pthread_mutex_lock(mutex) != 0) die("unexpected pthread_mutex_lock() failure!"); } That way usage would be more obvious and more familar to kernel developers :-) [ It would also open up the possibility, in the far future, to bring lockdep to user-space ;-) ] What do you think? Thanks, Ingo