From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 8985 invoked by alias); 2 May 2011 22:02:04 -0000 Received: (qmail 8971 invoked by uid 22791); 2 May 2011 22:02:03 -0000 X-SWARE-Spam-Status: No, hits=0.5 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_LOW,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from prod-mail-xrelay01.akamai.com (HELO prod-mail-xrelay01.akamai.com) (72.246.2.12) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 02 May 2011 22:01:47 +0000 Received: from prod-mail-xrelay01.akamai.com (localhost [127.0.0.1]) by postfix.imss70 (Postfix) with ESMTP id B5F7A47802D; Mon, 2 May 2011 22:01:46 +0000 (GMT) Received: from prod-mail-relay01.akamai.com (prod-mail-relay01.akamai.com [172.17.50.20]) by prod-mail-xrelay01.akamai.com (Postfix) with ESMTP id 96586478006; Mon, 2 May 2011 22:01:46 +0000 (GMT) Received: from usma1ex-cashub.kendall.corp.akamai.com (usma1ex-cashub1-nlb.kendall.corp.akamai.com [172.17.120.172]) by prod-mail-relay01.akamai.com (Postfix) with ESMTP id 87004226051; Mon, 2 May 2011 22:01:46 +0000 (GMT) Received: from usma1ex-cashub6.kendall.corp.akamai.com (172.27.66.71) by usma1ex-cashub1.kendall.corp.akamai.com (172.17.120.164) with Microsoft SMTP Server (TLS) id 8.3.137.0; Mon, 2 May 2011 18:01:46 -0400 Received: from USMBX1.msg.corp.akamai.com ([169.254.2.81]) by usma1ex-cashub6.kendall.corp.akamai.com ([172.27.66.71]) with mapi; Mon, 2 May 2011 18:01:45 -0400 From: "Lubashev, Igor" To: "Burkhardt, Glenn" , "pthreads-win32@sourceware.org" Date: Mon, 02 May 2011 22:02:00 -0000 Subject: RE: how to get thread priorities to work Message-ID: <83CE6FF8F6C9B2468A618FC2C512672605B4B88638@USMBX1.msg.corp.akamai.com> References: <83CE6FF8F6C9B2468A618FC2C512672605B4B8862E@USMBX1.msg.corp.akamai.com> In-Reply-To: Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-IsSubscribed: yes Mailing-List: contact pthreads-win32-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: pthreads-win32-owner@sourceware.org X-SW-Source: 2011/txt/msg00018.txt.bz2 Hope this answers the question of why the two threads are running at about = the same speed. -----Original Message----- From: Burkhardt, Glenn [mailto:Glenn.Burkhardt@goodrich.com]=20 Sent: Monday, May 02, 2011 6:00 PM To: Lubashev, Igor; pthreads-win32@sourceware.org Subject: RE: how to get thread priorities to work Dual core processor.=20 -----Original Message----- From: Lubashev, Igor [mailto:ilubashe@akamai.com]=20 Sent: Monday, May 02, 2011 5:51 PM To: Burkhardt, Glenn; pthreads-win32@sourceware.org Subject: RE: how to get thread priorities to work Without looking too much into this, are you trying this on a multi-core machine (either multiple cores or one hyperthreading core)?=20=20 - Igor -----Original Message----- From: pthreads-win32-owner@sourceware.org [mailto:pthreads-win32-owner@sourceware.org] On Behalf Of Burkhardt, Glenn Sent: Monday, May 02, 2011 5:43 PM To: pthreads-win32@sourceware.org Subject: how to get thread priorities to work I've been puzzling over this for way too long now. I can't seem to get thread priorities to work. Any help will be appreciated.=20=20 For the code that follows, I would expect that only one of the threads would run, and the counter for the lower priority thread would never increment. But that's not the case, on both a WinXP and Win7 system (built with MinGW 10/30/2010, gcc 4.5.2). The counter values for the two threads are close to being the same (e.g., 94686137, 99999999). TIA... #include #include #include #include #include void sleep10(int *cnt) { double x; for (int i=3D0; i < 100000000; i++) { x =3D sin(1.0/(1.0+i)); *cnt =3D i; } } void printError() { char *msg; int errorCode =3D GetLastError(); FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, 0, errorCode, 0, (LPTSTR)&msg, 0, 0); printf("error=3D%d: %s\n", errorCode, msg); LocalFree(msg); } void *thread(void *count) { =20 printf("%p: %d\n", count, GetThreadPriority(GetCurrentThread())); sleep10(count); =20 printf("%p exit\n", count); return 0; } int main() { struct sched_param spMax, spMin; pthread_attr_t attrMax, attrMin; pthread_t tMax, tMin; int minCount, maxCount; spMax.sched_priority =3D sched_get_priority_max(SCHED_OTHER); spMin.sched_priority =3D sched_get_priority_min(SCHED_OTHER); pthread_attr_init(&attrMax); pthread_attr_setschedparam(&attrMax, &spMax); pthread_attr_init(&attrMin); pthread_attr_setschedparam(&attrMin, &spMin); pthread_create(&tMax, &attrMax, thread, &maxCount); pthread_create(&tMin, &attrMin, thread, &minCount); printf("join %d\n", GetThreadPriority(GetCurrentThread())); pthread_join(tMax, 0); printf("%p: %d, %p: %d\n", &minCount, minCount, &maxCount, maxCount); return 0; }