From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 834 invoked by alias); 2 May 2011 21:51:51 -0000 Received: (qmail 806 invoked by uid 22791); 2 May 2011 21:51:49 -0000 X-SWARE-Spam-Status: No, hits=-1.8 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-xrelay03.akamai.com (HELO prod-mail-xrelay03.akamai.com) (96.6.114.84) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 02 May 2011 21:51:31 +0000 Received: from prod-mail-xrelay03.akamai.com (localhost [127.0.0.1]) by postfix.imss70 (Postfix) with ESMTP id 097723C401D; Mon, 2 May 2011 21:51:31 +0000 (GMT) Received: from prod-mail-relay03.akamai.com (prod-mail-relay03.akamai.com [172.27.8.26]) by prod-mail-xrelay03.akamai.com (Postfix) with ESMTP id E47A93C4009; Mon, 2 May 2011 21:51:30 +0000 (GMT) Received: from usma1ex-cashub.kendall.corp.akamai.com (unknown [172.17.120.191]) by prod-mail-relay03.akamai.com (Postfix) with ESMTP id C013D2FD68; Mon, 2 May 2011 21:51:30 +0000 (GMT) Received: from USMBX1.msg.corp.akamai.com ([169.254.2.81]) by USMA1EX-CASHUB4.kendall.corp.akamai.com ([172.17.120.191]) with mapi; Mon, 2 May 2011 17:51:30 -0400 From: "Lubashev, Igor" To: "Burkhardt, Glenn" , "pthreads-win32@sourceware.org" Date: Mon, 02 May 2011 21:51:00 -0000 Subject: RE: how to get thread priorities to work Message-ID: <83CE6FF8F6C9B2468A618FC2C512672605B4B8862E@USMBX1.msg.corp.akamai.com> References: 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/msg00016.txt.bz2 Without looking too much into this, are you trying this on a multi-core mac= hine (either multiple cores or one hyperthreading core)?=20=20 - Igor -----Original Message----- From: pthreads-win32-owner@sourceware.org [mailto:pthreads-win32-owner@sour= ceware.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; }