X-Recipient: archive-cygwin AT delorie DOT com X-Spam-Check-By: sourceware.org X-SBRS: 3.6 X-IronPort-AV: E=Sophos;i="4.31,302,1215414000"; d="scan'208";a="44751477" From: Richard Stanton To: "cygwin AT cygwin DOT com" Date: Sun, 3 Aug 2008 22:03:20 -0700 Subject: cygwin gcc: Different numerical results in thread vs in main() Message-ID: <40C7B1BFC291ED4E9D10436D07736A33127AB73C9D@EXMAIL7.haas.uc.berkeley.edu> Accept-Language: en-US Content-Language: en-US acceptlanguage: en-US Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by delorie.com id m7454Jei030025 The following program performs exactly the same calculation 5 times, once inside main(), and again in 4 thread functions. Though the calculations are identical, the results are not. When I compile and run the same program on my Mac, all the results are identical. By the way, this is using the latest gcc 3.4.4. Richard Stanton ------------------ [c:\projects\threads]thread1 Main: t/1+t = 0.0005609048868329022342546 Thread 0: t/1+t = 0.0005609048868329021258344 Thread 1: t/1+t = 0.0005609048868329021258344 Thread 2: t/1+t = 0.0005609048868329021258344 Thread 3: t/1+t = 0.0005609048868329021258344 #include #include #define NUM_THREADS 4 double t = 0.0005612196776927068104374; void * thread_function (void *arg) { int i; int id = *((int *)arg); printf("Thread %d: t/1+t = %30.25lf\n", id, t/(1.0+t)); return NULL; } int main() { int i; int arg[NUM_THREADS] = {0,1,2,3}; pthread_t thread[NUM_THREADS]; pthread_attr_t attr; printf("Main: t/1+t = %30.25lf\n", t/(1.0+t)); /* initialize and set the thread attributes */ pthread_attr_init( &attr ); pthread_attr_setdetachstate( &attr, PTHREAD_CREATE_JOINABLE ); /* creating threads */ for ( i=0; i