Date: Sat, 27 Nov 1999 21:43:08 -0500 From: Dan Moschuk <dan@FreeBSD.ORG> To: FengYue <fengyue@bluerose.windmoon.nu> Cc: hackers@FreeBSD.ORG Subject: Re: PThreads and Sockets Message-ID: <19991127214308.A27972@november.jaded.net> In-Reply-To: <Pine.BSF.4.10.9911271507450.42278-100000@bluerose.windmoon.nu>; from FengYue on Sat, Nov 27, 1999 at 03:11:36PM -0800 References: <19991126173228.A2608@spirit.jaded.net> <Pine.BSF.4.10.9911271507450.42278-100000@bluerose.windmoon.nu>
next in thread | previous in thread | raw e-mail | index | archive | help
| > Try this.
| >
| > void *serverstart(void *ptr)
| > {
| > int sd2;
| >
| > sd2 = *((int *) ptr);
| > ...
| > }
|
| There is a race condition. You're passing sd2's address to serverstart()
| and inside serverstart() you def' the pointer. What if
| "sd2=accept(sd, (struct sockaddr*)&cad, &alen)" gets
| executed before your previous serverstart() finishs "sd2 = *((int*)ptr)"?
Since accept isn't atomic, it would be best to enclose the whole sha-bang in
a mutex up until the sd2 = *((int *) ptr) call finishes.
--
Dan Moschuk (TFreak!dan@freebsd.org)
"Try not. Do, or do not. There is no try."
-- Yoda
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?19991127214308.A27972>
