From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 7752 invoked by alias); 2 May 2011 22:00:42 -0000 Received: (qmail 7741 invoked by uid 22791); 2 May 2011 22:00:39 -0000 X-SWARE-Spam-Status: No, hits=-1.1 required=5.0 tests=AWL,BAYES_00,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from phx-mxvgateway.goodrich.com (HELO phx-mxv1gateway.goodrich.com) (63.241.174.110) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 02 May 2011 22:00:26 +0000 Received: from GR-GWI-WEST-A.goodrich.com (gr-gwi-west-a.goodrich.com [170.126.245.4]) by phx-mxv1gateway.goodrich.com (Symantec Brightmail Gateway) with SMTP id C5.B0.26438.9792FBD4; Mon, 2 May 2011 18:00:25 -0400 (EDT) Received: from NHC1EX21.goodrich.root.local ([170.126.120.70]) by GR-GWI-WEST-A.goodrich.com (8.13.5/8.13.5) with ESMTP id p42M0Ple019233; Mon, 2 May 2011 18:00:25 -0400 (EDT) Received: from nhc0ex17.goodrich.root.local ([170.126.246.106]) by NHC1EX21.goodrich.root.local with Microsoft SMTPSVC(6.0.3790.4675); Mon, 2 May 2011 18:00:24 -0400 Content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Subject: RE: how to get thread priorities to work Date: Mon, 02 May 2011 22:00:00 -0000 Message-ID: In-Reply-To: <83CE6FF8F6C9B2468A618FC2C512672605B4B8862E@USMBX1.msg.corp.akamai.com> References: <83CE6FF8F6C9B2468A618FC2C512672605B4B8862E@USMBX1.msg.corp.akamai.com> From: "Burkhardt, Glenn" To: "Lubashev, Igor" , 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/msg00017.txt.bz2 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; }