From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1JYKAo-0005ga-MS for qemu-devel@nongnu.org; Sun, 09 Mar 2008 07:58:38 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1JYKAm-0005fW-SI for qemu-devel@nongnu.org; Sun, 09 Mar 2008 07:58:38 -0400 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1JYKAm-0005fI-Nq for qemu-devel@nongnu.org; Sun, 09 Mar 2008 07:58:36 -0400 Received: from mail2.shareable.org ([80.68.89.115]) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1JYKAm-0003Fi-FV for qemu-devel@nongnu.org; Sun, 09 Mar 2008 07:58:36 -0400 Date: Sun, 9 Mar 2008 11:58:26 +0000 From: Jamie Lokier Subject: Re: [Qemu-devel] [PATCH] use a thread id variable Message-ID: <20080309115826.GA8077@shareable.org> References: <12047472711034-git-send-email-gcosta@redhat.com> <12047472772114-git-send-email-gcosta@redhat.com> <47D3AD53.6030809@codefidence.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <47D3AD53.6030809@codefidence.com> Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: kvm-devel@lists.sourceforge.net, glommer@gmail.com, chrisw@sous-sol.org, Glauber Costa Gilad Ben-Yossef wrote: > Glauber Costa wrote: > >This patch introduces a "thread_id" variable to CPUState. > >It's duty will be to hold the process, or more generally, thread > >id of the current executing cpu > > > > env->nb_watchpoints = 0; > >+#ifdef __WIN32 > >+ env->thread_id = GetCurrentProcessId(); > >+#else > >+ env->thread_id = getpid(); > >+#endif > > *penv = env; > > hmm... maybe I'm missing something, but in Linux at least I think you > would prefer this to be gettid() rather then getpid as each CPU has it's > own thread, not a different process. On most platforms, getpid() returns the same value for all threads, so it's not useful as a thread id. On Linux, it depends which version of threads. The old package, LinuxThreads, has different getpid() for each thread. The current one, NPTL, has them all the same. What you're supposed to do with pthreads in general is use pthread_self(). Btw, unfortunately pthread_self() is not safe to call from signal handlers. -- Jamie