From owner-freebsd-threads@FreeBSD.ORG Wed Jul 9 19:47:13 2003 Return-Path: Delivered-To: freebsd-threads@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 21CCC37B401 for ; Wed, 9 Jul 2003 19:47:13 -0700 (PDT) Received: from mail.pcnet.com (mail.pcnet.com [204.213.232.4]) by mx1.FreeBSD.org (Postfix) with ESMTP id 62E6D43FB1 for ; Wed, 9 Jul 2003 19:47:12 -0700 (PDT) (envelope-from eischen@vigrid.com) Received: from mail.pcnet.com (mail.pcnet.com [204.213.232.4]) by mail.pcnet.com (8.12.8/8.12.1) with ESMTP id h6A2lBAI010072; Wed, 9 Jul 2003 22:47:11 -0400 (EDT) Date: Wed, 9 Jul 2003 22:47:10 -0400 (EDT) From: Daniel Eischen X-Sender: eischen@pcnet5.pcnet.com To: Brooks Davis In-Reply-To: <20030710001744.GA7135@Odin.AC.HMC.Edu> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII cc: freebsd-threads@freebsd.org Subject: Re: null pthread_t X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list Reply-To: deischen@freebsd.org List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 10 Jul 2003 02:47:13 -0000 On Wed, 9 Jul 2003, Brooks Davis wrote: > I've got some Linux pthread code that goes something like this that I'm > porting to FreeBSD: > > ------ > pthread_t tid; > > tid = -1; > > /* Do stuff including maybe creating a thread. */ > > if (tid != -1) { > pthread_cancel(tid); > pthread_join(tid, NULL); > } > ------ > > Since FreeBSD uses pointers instead of integers for pthread_t's, this > generates warnings which go away if you replace -1 with NULL, but > it seems like that is likely to do bad things on linux. Is there a > portable NULL-equivalent pthread_t? I'm not seeing anything jump out at > me in the headers. The code in question shouldn't be doing that. If it needs to know whether a thread id is valid, it should have a separate flag for it (tid_valid) or possibly use pthread_kill(tid, 0) and checking the return value (sending signal 0 to a thread is akin to sending a process signal 0; the signal isn't delivered but the process id is checked for validity). -- Dan Eischen