From owner-freebsd-stable@FreeBSD.ORG Wed Nov 9 14:19:20 2011 Return-Path: Delivered-To: freebsd-stable@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 2BA02106564A for ; Wed, 9 Nov 2011 14:19:20 +0000 (UTC) (envelope-from unga888@yahoo.com) Received: from nm1.bullet.mail.bf1.yahoo.com (nm1.bullet.mail.bf1.yahoo.com [98.139.212.160]) by mx1.freebsd.org (Postfix) with SMTP id C1C648FC17 for ; Wed, 9 Nov 2011 14:19:19 +0000 (UTC) Received: from [98.139.212.153] by nm1.bullet.mail.bf1.yahoo.com with NNFMP; 09 Nov 2011 14:06:01 -0000 Received: from [98.139.212.248] by tm10.bullet.mail.bf1.yahoo.com with NNFMP; 09 Nov 2011 14:06:01 -0000 Received: from [127.0.0.1] by omp1057.mail.bf1.yahoo.com with NNFMP; 09 Nov 2011 14:06:01 -0000 X-Yahoo-Newman-Property: ymail-3 X-Yahoo-Newman-Id: 804208.66910.bm@omp1057.mail.bf1.yahoo.com Received: (qmail 56350 invoked by uid 60001); 9 Nov 2011 14:06:00 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s1024; t=1320847560; bh=Unao6qo8+R4xfAn0rGs6PV2+HixzKz6cwkdAh1yqYo4=; h=X-YMail-OSG:Received:X-Mailer:Message-ID:Date:From:Reply-To:Subject:To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=wrXad5Bk8hXJGfyWY+2hZXZA3fSQhLwGoGqGg9BRzJB4IgzRYLcmxSs8CzdJsbc4n0GNb98Id6Mp6DI9ahYluGndOEKOVarDvx1qMrRruAJ78RpFknOHzG5Wfk6zdQSaWwOmr+8N/5oLoFptFJxzOpPCTkoZDfz61xAFySeynLw= DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=X-YMail-OSG:Received:X-Mailer:Message-ID:Date:From:Reply-To:Subject:To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=zJWxDcaW8G8k8zqEz4SjBiUOkToWwN8uuG9n1dFny2qE8hmiSwMRRDs2GpwW/EOaZFeHHp4tWRZS0TlDDeh6cvXO88TE1Cd1AJPC+tp29/mLeniRTHJk0STP0Kop5IinDRYWprGOpjIZQVBEJEgLtkzDmd/jxUCaMS7UX2SuujM=; X-YMail-OSG: oonjztoVM1ld7cE4j7aZp2VotpSN1Sgq2WByzGBTnmB6RqQ aQYhJgtJwtkPRy5Jr3qUni9KlN1l4gfxKt2eSnvvYUGEScSByeQ0rm4s10D9 sNBptnoU_3ZyS4sqc1HzMfPf7OZ3WLltyDuhD0ScB8PUW4dyZm6Nh1c7tAs5 hOhL6SRFJRFsabK4dm.EP2nSE9Ii8e4D_t_MChwZclEUtJjTTDQu3bNXd2NT 3iV0ji0vFRe7Uer4L0JUwE_0cJ4aamlFKB0hrI4jPEQeq4RIUKq1Im59ZJTO ysPS59MW4ipN8GJ2KM_PPGfeE8hP_fHXbww_rCYSvR37bERbwVYt.Xp.sNVq 4rtbEYgr3UUA0aI3pvCo6HHhhQKaoBIq6zoVxZiN6Y4.hqjfe_P1_UxRDjvG DCS3rRUOiUZmEpLWyYzu2SmHGfVqhtd37Ucs0AQlOI0g1HWskMKByuqXltxE vYPXgbjNkY8Ky_knjpgMCfuz.e7Jk7HFr_4n6yxvugo_QwiR.F3vx64jEbk2 VNEU6DutzhA8_CrQy9t668.cRe2faO.9cZ2mm310yRNh88w-- Received: from [116.15.157.180] by web160114.mail.bf1.yahoo.com via HTTP; Wed, 09 Nov 2011 06:06:00 PST X-Mailer: YahooMailWebService/0.8.115.325013 Message-ID: <1320847560.49916.YahooMailNeo@web160114.mail.bf1.yahoo.com> Date: Wed, 9 Nov 2011 06:06:00 -0800 (PST) From: Unga To: "freebsd-stable@freebsd.org" MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable Subject: pthreads mostly hang when signal X-BeenThere: freebsd-stable@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Unga List-Id: Production branch of FreeBSD source code List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 09 Nov 2011 14:19:20 -0000 Hi all=0A=0AI have a C program with pthreads.=0A=0AThis program creates tho= usands of detached pthreads for short jobs at the beginning. They all come = and go within the first 10 seconds.=0A=0A=0ABut it has 3 permanently runnin= g pthreads.=0A=0AI signal these 3 permanently running pthreads to stop proc= essing. I send SIGUSR1 for this purpose.=0A=0AIf I don't interrupt these 3 = permanently running pthreads, they run without any issue and do their job.= =0A=0AIf I send the SIGUSR1 to these 3 permanently running pthreads, they r= arely work. That is, these threads immediately receive SIGUSR1 signals.=0A= =0ABut when I signal, they mostly hang. That is, these threads don't receiv= e the signal.=0A=0A=0AFollowing code fragment shows how I send the signal a= nd wait till they stop:=0A=A0=A0=A0=A0 LockMutex(threadCountMutex);=A0=A0 = =0A=A0=A0=A0=A0 tCount =3D threadCount;=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0 =0A=A0=A0=A0=A0 UnlockMutex(threadCountMutex); =0A=A0=0A=A0=A0=A0=A0 pr= intf("B4 stop Thread_1. Threads: %d\n", tCount); =0A=A0=A0=A0=A0 =0A=A0=A0= =A0=A0 LockMutex(Thread_1varMutex);=0A=A0=A0=A0 Thread_1var.Thread_1Stopped= =3D 0; // Thread_1 not stopped yet.=0A=A0=A0=A0=A0 UnlockMutex(Thread_1var= Mutex);=0A=0A=0A=A0=A0=A0=A0 if (pthread_kill(tid1, SIGUSR1) !=3D 0) // Sen= d a signal to the thread=0A=A0=A0=A0=A0=A0=A0=A0 {=A0=A0=A0 =A0=A0=A0 =A0= =A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 // to stop proces= sing.=0A=A0=A0=A0=A0=A0=A0=A0=A0 fprintf(stderr, "pthread_kill failed for T= hread_1!\n");=0A=A0=A0=A0=A0=A0=A0=A0=A0 exit(1);=0A=A0=A0=A0=A0=A0=A0=A0 }= =0A=A0=A0=A0 Delay(25); // Let Thread_1 to settle.=0A=0A=0A=A0=A0=A0=A0 // = Check now whether the Thread_1 thread received the signal and stopped proce= ssing.=0A=A0=A0=A0=A0 for (threadActivateDelay=3D0 ;threadActivateDelay < t= hreadActivateTimeOut; threadActivateDelay +=3D 50)=0A=A0=A0=A0=A0 {=0A=A0= =A0=A0=A0=A0 LockMutex(Thread_1varMutex);=0A=A0=A0=A0=A0=A0 Thread_1Stopped= =3D Thread_1var.Thread_1Stopped;=0A=A0=A0=A0=A0=A0 UnlockMutex(Thread_1var= Mutex);=0A=A0=A0=A0=A0=A0 =0A=A0=A0=A0=A0=A0 if (Thread_1Stopped)=0A=A0=A0= =A0=A0=A0=A0=A0=A0 break;=0A=A0=A0=A0=A0=A0 else=0A=A0=A0=A0=A0=A0=A0=A0=A0= Delay(50); // Let Thread_1 thread to settles. 50ms=0A=0A=A0=A0=A0=A0=A0 Lo= ckMutex(threadCountMutex);=A0=A0 =0A=A0=A0=A0=A0=A0 tCount =3D threadCount;= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 =0A=A0=A0=A0=A0=A0 UnlockMutex(thre= adCountMutex); =0A=A0=A0=A0 =A0=0A=A0=A0=A0=A0=A0 printf("Wait till Thread_= 1 stopped, Threads: %d=A0 Delay: %d\n", tCount, threadActivateDelay+50); = =A0=A0=A0 =0A=A0=A0=A0=A0 }=0A=0A=A0=A0=A0=A0 printf("Came out of Thread_1 = loop, threadActivateDelay: %d, threadActivateTimeOut: %d\n", threadActivate= Delay, threadActivateTimeOut); =0A=A0=A0=A0=A0 if (threadActivateDelay >=3D= threadActivateTimeOut) // Something is wrong. Thread may be dead.=0A=A0=A0= =A0=A0=A0=A0=A0 {=0A=A0=A0=A0 =A0fprintf(stderr, "Time out. Thread_1 may be= dead!\n");=0A=A0=A0=A0=A0=A0=A0=A0=A0 exit(1);=0A=A0=A0=A0=A0=A0=A0=A0 }= =0A=0A=0ANote, Thread_1var.Thread_1Stopped is set to 1 by the Thread_1 once= it receive the SIGUSR1.=0A=0AResult of two runs of the program is as follo= ws (values are in milliseconds):=0A./prog=0AB4 stop Thread_1. Threads: 3=0A= Thread_1 cought SIGUSR1=0AWait till Thread_1 stopped, Threads: 3=A0 Delay: = 50=0ACame out of Thread_1 loop, threadActivateDelay: 50, threadActivateTime= Out: 3000=0AB4 stop Thread_2. Threads: 3=0AThread_2 cought SIGUSR1=0ACame o= ut of Thread_2 loop, threadActivateDelay: 0, threadActivateTimeOut: 3000=0A= B4 stop Thread_3. Threads: 3=0AWait till Thread_3 stopped, Threads: 3=A0 De= lay: 50=0AWait till Thread_3 stopped, Threads: 3=A0 Delay: 100=0AWait till = Thread_3 stopped, Threads: 3=A0 Delay: 150=0A:=0A:=0AWait till Thread_3 sto= pped, Threads: 3=A0 Delay: 3000=0ACame out of Thread_3 loop, threadActivate= Delay: 3000, threadActivateTimeOut: 3000=0ATime out. Thread_3 may be dead!= =0A=0A=0A=0A./prog=0AB4 stop Thread_1. Threads: 3=0AWait till Thread_1 stop= ped, Threads: 3=A0 Delay: 50=0AWait till Thread_1 stopped, Threads: 3=A0 De= lay: 100=0AWait till Thread_1 stopped, Threads: 3=A0 Delay: 150=0A:=0A:=0AW= ait till Thread_1 stopped, Threads: 3=A0 Delay: 3000=0ACame out of Thread_1= loop, threadActivateDelay: 3000, threadActivateTimeOut: 3000=0ATime out. T= hread_1 may be dead!=0A=0A=0AI have tested this program on FreeBSD 8.1 and = 9.0 RC1, both i386. Different runs hang different threads. Also as I mentio= n earlier, rarely all three threads stop immediately.=0A=0AMy issue is quit= e similar to the problem: http://security.freebsd.org/advisories/FreeBSD-EN= -10:02.sched_ule.asc=0A=0ABut it doesn't freeze the system.=A0=0A=0AIncreas= e threadActivateTimeOut to 60000ms also doesn't work once hang.=0A=0APlease= also note, once receive a SIGUSR1, the thread wait on sigwait() till it re= ceive another signal.=0A=0A=0ASo what have I hit with? Is it a programming = error in my side or scheduling error or something else?=0A=0AAppreciate ver= y much if FreeBSD guys could help me to solve this issue.=0A=0AMany thanks = in advance.=0A=0ABest regards=0AUnga