-/*
- This file is part of drd, a data race detector.
+/* Test data race detection between floating point variables. */
- Copyright (C) 2006-2008 Bart Van Assche
- bart.vanassche@gmail.com
-
- This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License as
- published by the Free Software Foundation; either version 2 of the
- License, or (at your option) any later version.
-
- This program is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
- 02111-1307, USA.
-
- The GNU General Public License is contained in the file COPYING.
-*/
-
-// Test data race detection between floating point variables.
#include <assert.h>
-#include <stdio.h> // printf()
+#include <stdio.h> /* printf() */
#include <pthread.h>
-#include <unistd.h> // usleep()
-
+#include <unistd.h> /* usleep() */
-// Local functions declarations.
+/* Local functions declarations. */
static void* thread_func(void*);
-// Local variables.
-// s_mutex protects s_d3.
+/* Local variables. */
+
+/* s_mutex protects s_d3. */
static pthread_mutex_t s_mutex;
-static double s_d1; // accessed before thread creation and in the created
- // thread (not a race).
-static double s_d2; // accessed in the created thread and after the join
- // (not a race).
-static double s_d3; // accessed simultaneously from both threads (race).
+static double s_d1; /* accessed before thread creation and in the created */
+ /* thread (not a race). */
+static double s_d2; /* accessed in the created thread and after the join */
+ /* (not a race). */
+static double s_d3; /* accessed simultaneously from both threads (race). */
static int s_debug = 0;
static int s_do_printf = 0;
static int s_use_mutex = 0;
-// Function definitions.
+/* Function definitions. */
int main(int argc, char** argv)
{
pthread_mutex_init(&s_mutex, 0);
- // Switch to line-buffered mode, such that timing information can be
- // obtained for each printf() call with strace.
+ /*
+ * Switch to line-buffered mode, such that timing information can be
+ * obtained for each printf() call with strace.
+ */
setlinebuf(stdout);
if (s_debug)
s_d3 = 3;
pthread_create(&threadid, 0, thread_func, 0);
- // Wait until the printf() in the created thread finished.
{
if (s_use_mutex) pthread_mutex_lock(&s_mutex);
if (s_use_mutex) pthread_mutex_unlock(&s_mutex);
}
- // Wait until the thread finished.
- //printf("Before call to pthread_join()\n");
- //fflush(stdout);
+ /* Wait until the thread finished. */
pthread_join(threadid, 0);
- //printf("After call to pthread_join()\n");
- //fflush(stdout);
if (s_do_printf) printf("s_d2 = %g (should be 2)\n", s_d2);
if (s_do_printf) printf("s_d3 = %g (should be 5)\n", s_d3);
Conflicting load by thread 1/1 at 0x........ size 8
at 0x........: main (fp_race.c:?)
Location 0x........ is 0 bytes inside local var "s_d3"
-declared at fp_race.c:47, in frame #? of thread 1
+declared at fp_race.c:24, in frame #? of thread 1
Other segment start (thread 0/2)
(thread finished, call stack no longer available)
Other segment end (thread 0/2)
Conflicting store by thread 1/1 at 0x........ size 8
at 0x........: main (fp_race.c:?)
Location 0x........ is 0 bytes inside local var "s_d3"
-declared at fp_race.c:47, in frame #? of thread 1
+declared at fp_race.c:24, in frame #? of thread 1
Other segment start (thread 0/2)
(thread finished, call stack no longer available)
Other segment end (thread 0/2)
-/** Test whether detached threads are handled properly.
- * Copyright (c) 2006-2008 by Bart Van Assche (bart.vanassche@gmail.com).
- */
+/* Test whether detached threads are handled properly. */
#include <assert.h>
-/** Test whether detached threads are handled properly.
- * This test program is based on pth_detached.c, with the difference that
- * in this test program the main thread uses a counting semaphore instead
- * of a counter protected by a mutex to wait until all detached threads
- * finished.
- * Copyright (c) 2006-2008 by Bart Van Assche (bart.vanassche@gmail.com).
+/**
+ * Test whether detached threads are handled properly.
+ * This test program is based on pth_detached.c, with the difference that
+ * in this test program the main thread uses a counting semaphore instead
+ * of a counter protected by a mutex to wait until all detached threads
+ * finished.
*/
-/*
- This file is part of drd, a data race detector.
+/* Use a semaphore to implement mutual exclusion. */
- Copyright (C) 2006-2008 Bart Van Assche
- bart.vanassche@gmail.com
-
- This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License as
- published by the Free Software Foundation; either version 2 of the
- License, or (at your option) any later version.
-
- This program is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
- 02111-1307, USA.
-
- The GNU General Public License is contained in the file COPYING.
-*/
-
-// Use a semaphore to implement mutual exclusion.
#include <assert.h>
-#include <stdio.h> // printf()
+#include <stdio.h> /* printf() */
#include <pthread.h>
#include <semaphore.h>
-#include <unistd.h> // usleep()
-
+#include <unistd.h> /* usleep() */
-// Local functions declarations.
+/* Local functions declarations. */
static void* thread_func(void*);
-// Local variables.
-// s_sem protects s_d3.
+/* Local variables. */
+
+/* s_sem protects s_d3. */
static sem_t s_sem;
-static double s_d1; // accessed before thread creation and in the created
- // thread (not a race).
-static double s_d2; // accessed in the created thread and after the join
- // (not a race).
-static double s_d3; // accessed simultaneously from both threads (race).
+static double s_d1; /* accessed before thread creation and in the created */
+ /* thread (not a race). */
+static double s_d2; /* accessed in the created thread and after the join */
+ /* (not a race). */
+static double s_d3; /* accessed simultaneously from both threads (race). */
static int s_debug = 0;
static int s_do_printf = 0;
static int s_do_mutual_exclusion = 0;
-// Function definitions.
+/* Function definitions. */
int main(int argc, char** argv)
{
sem_init(&s_sem, 0, 1);
- // Switch to line-buffered mode, such that timing information can be
- // obtained for each printf() call with strace.
+ /*
+ * Switch to line-buffered mode, such that timing information can be
+ * obtained for each printf() call with strace.
+ */
setlinebuf(stdout);
if (s_debug)
s_d3 = 3;
pthread_create(&threadid, 0, thread_func, 0);
- // Wait until the printf() in the created thread finished.
{
if (s_do_mutual_exclusion) sem_wait(&s_sem);
if (s_do_mutual_exclusion) sem_post(&s_sem);
}
- // Wait until the thread finished.
- //printf("Before call to pthread_join()\n");
- //fflush(stdout);
+ /* Wait until the thread finished. */
pthread_join(threadid, 0);
- //printf("After call to pthread_join()\n");
- //fflush(stdout);
if (s_do_printf) printf("s_d2 = %g (should be 2)\n", s_d2);
if (s_do_printf) printf("s_d3 = %g (should be 5)\n", s_d3);
Conflicting load by thread 1/1 at 0x........ size 8
at 0x........: main (sem_as_mutex.c:?)
Location 0x........ is 0 bytes inside local var "s_d3"
-declared at sem_as_mutex.c:48, in frame #? of thread 1
+declared at sem_as_mutex.c:25, in frame #? of thread 1
Other segment start (thread 0/2)
(thread finished, call stack no longer available)
Other segment end (thread 0/2)
Conflicting store by thread 1/1 at 0x........ size 8
at 0x........: main (sem_as_mutex.c:?)
Location 0x........ is 0 bytes inside local var "s_d3"
-declared at sem_as_mutex.c:48, in frame #? of thread 1
+declared at sem_as_mutex.c:25, in frame #? of thread 1
Other segment start (thread 0/2)
(thread finished, call stack no longer available)
Other segment end (thread 0/2)