From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35550) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WgCc3-0006d4-1Y for qemu-devel@nongnu.org; Fri, 02 May 2014 08:30:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WgCbw-0005Ii-NL for qemu-devel@nongnu.org; Fri, 02 May 2014 08:30:46 -0400 Received: from isrv.corpit.ru ([86.62.121.231]:44674) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WgCbw-0005IU-27 for qemu-devel@nongnu.org; Fri, 02 May 2014 08:30:40 -0400 Message-ID: <53638FEE.5000908@msgid.tls.msk.ru> Date: Fri, 02 May 2014 16:30:38 +0400 From: Michael Tokarev MIME-Version: 1.0 References: <536378E7.1090408@msgid.tls.msk.ru> <20140502110141.GQ22878@redhat.com> In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH 2/3] glib: add g_thread_new() compat function List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Peter Maydell , "Daniel P. Berrange" Cc: qemu-devel , Stefan Hajnoczi 02.05.2014 15:08, Peter Maydell wrote: > On 2 May 2014 12:01, Daniel P. Berrange wrote: >> On Fri, May 02, 2014 at 02:52:23PM +0400, Michael Tokarev wrote: >>> Stefan Hajnoczi: >>>> +#if !GLIB_CHECK_VERSION(2, 31, 0) >>>> +static inline GThread *g_thread_new(const gchar *unused, >>>> + GThreadFunc func, >>>> + gpointer data) >>>> +{ >>>> + GThread *thread = g_thread_create(func, data, TRUE, NULL); >>>> + if (!thread) { >>>> + g_error("g_thread_create failed"); >>>> + } >>>> + return thread; >>>> +} >>>> +#endif >>> >>> About g_error(): >>> >>> "This function will result in a core dump; don't use it for errors you expect. >>> Using this function indicates a bug in your program, i.e. an assertion failure." >>> >>> I'm not sure if this is like an assertion failure, probably yes. But we should >>> not, I think, dump core in this situation. Is there a glib function that does >>> (fatal) error reporting but does NOT dump core? >> >> I think that's what g_critical is intended for. It is more severe than >> g_warning, but won't exit or abort the process. > > I'm not convinced we should be emitting any kind of > warning message here anyway -- surely it's up to the > caller to handle thread creation failure? The glib > warning/error functions presumably print to stderr, > which has all the usual issues with possibly messing > up guest output. Actually the whole point is moot. Here's what g_thread_new() does (in 2.31+): GThread * g_thread_new (const gchar *name, GThreadFunc func, gpointer data) { GError *error = NULL; GThread *thread; thread = g_thread_new_internal (name, g_thread_proxy, func, data, 0, &error); if G_UNLIKELY (thread == NULL) g_error ("creating thread '%s': %s", name ? name : "", error->message); return thread; } So that's what we should use in our g_thread_new() impl, and this is what Stefan used, in a slightly less complex way. I'll add this to my wrapper too. Thanks, /mjt