MayAlsofyani commited on
Commit
b06a65a
·
verified ·
1 Parent(s): daac0f1

Upload imbalanced_bug.csv

Browse files
Files changed (1) hide show
  1. imbalanced_bug.csv +45 -189
imbalanced_bug.csv CHANGED
@@ -3985,112 +3985,65 @@ int main(int argc, const char *argv[])
3985
  exit(EXIT_SUCCESS);
3986
  }
3987
  ",0
3988
- "#include <stdio.h>
3989
- #include <stdlib.h>
3990
  #include <pthread.h>
3991
- #include <math.h>
 
 
3992
 
3993
- #define NUM_THREADS 2 /* default number of threads */
3994
 
3995
- /* Shared global variables. All threads can access them. */
3996
- float hypotenuse;
3997
- pthread_mutex_t mutexsum;
 
3998
 
 
 
3999
 
4000
- void *square_side (void *);
 
4001
 
 
 
 
 
 
 
4002
 
4003
- int main (int argc, char **argv)
4004
- {
4005
- int i; /* loop variable */
4006
- float sides[2]; /* right-angled triangle sides */
4007
- pthread_t *thr_ids; /* array of thread ids */
4008
-
4009
- switch (argc) /* check command line arguments */
4010
- {
4011
- case 3:
4012
- /* Get the values of the right-angled triangle sides */
4013
- sides[0] = atof (argv[1]);
4014
- sides[1] = atof (argv[2]);
4015
- if ((sides[0] < 1) || (sides[1] < 1))
4016
- {
4017
- fprintf (stderr, ""Error: wrong values for triangle sides.\\n""
4018
- ""Usage:\\n""
4019
- "" %s <side_a> <side_b>\\n""
4020
- ""values of sizes should be > 0\\n"",
4021
- argv[0]);
4022
- exit (EXIT_FAILURE);
4023
- }
4024
- break;
4025
 
4026
- default:
4027
- fprintf (stderr, ""Error: wrong number of parameters.\\n""
4028
- ""Usage:\\n""
4029
- "" %s <side_a> <side_b>\\n"",
4030
- argv[0]);
4031
- exit (EXIT_FAILURE);
4032
- }
4033
-
4034
- /* allocate memory for all dynamic data structures */
4035
- thr_ids = (pthread_t *) malloc (NUM_THREADS * sizeof (pthread_t));
4036
-
4037
- /* Validate that memory was successfully allocated */
4038
- if (thr_ids == NULL)
4039
- {
4040
- fprintf (stderr, ""File: %s, line %d: Can't allocate memory."",
4041
- __FILE__, __LINE__);
4042
- exit (EXIT_FAILURE);
4043
- }
4044
-
4045
- printf (""\\nPythagoras' theorem | a^2 + b^2 = c^2 \\n"");
4046
- hypotenuse = 0;
4047
-
4048
- /* Initialize the mutex to protect share data (hypotenuse) */
4049
- pthread_mutex_init (&mutexsum, NULL);
4050
-
4051
- /* Create the threads and calculate the squares on the sides */
4052
- pthread_create (&thr_ids[0], NULL, square_side, &sides[0]);
4053
- pthread_create (&thr_ids[1], NULL, square_side, &sides[1]);
4054
-
4055
- /* Using join to syncronize the threads */
4056
- for (i = 0; i < NUM_THREADS; i++)
4057
- {
4058
- pthread_join (thr_ids[i], NULL);
4059
- }
4060
-
4061
- printf (""Hypotenuse is %.2f\\n"", sqrt(hypotenuse));
4062
 
4063
- /* Deallocate any memory or resources associated */
4064
- pthread_mutex_destroy (&mutexsum);
4065
- free (thr_ids);
4066
 
4067
- return EXIT_SUCCESS;
 
4068
  }
4069
 
 
 
 
4070
 
4071
- /* square_side runs as a thread and calculates the areas of the
4072
- * square on the side, then sums the value to the hypotenuse.
4073
- * It uses a mutex to protect the hypotenuse and avoid a race
4074
- * conditiong within the threads.
4075
- *
4076
- * Input: arg pointer to triangle side value
4077
- * Return value: none
4078
- *
4079
- */
4080
- void *square_side (void *arg)
4081
- {
4082
- float side;
4083
 
4084
- /* Get the value of the triangle side and print the square */
4085
- side = *( ( float* )arg );
4086
- printf (""%.2f^2 = %.2f\\n"", side, side * side);
4087
-
4088
- /* Mutex lock/unlock to safely update the value of hypotenuse */
4089
- pthread_mutex_lock (&mutexsum);
4090
- hypotenuse += side * side;
4091
- pthread_mutex_unlock (&mutexsum);
4092
-
4093
- pthread_exit (EXIT_SUCCESS); /* Terminate the thread */
4094
  }
4095
  ",1
4096
  "#include <stdio.h>
@@ -4365,67 +4318,6 @@ int main(int argc, char* argv[]) {
4365
  return 0;
4366
  }
4367
  ",0
4368
- "#define _GNU_SOURCE /* To get pthread_getattr_np() declaration */
4369
- #include <assert.h>
4370
- #include <pthread.h>
4371
- #include <stdio.h>
4372
- #include <stdlib.h>
4373
- #include <unistd.h>
4374
-
4375
- pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
4376
-
4377
- void show_stack(pthread_attr_t *attr, pthread_t thread, char *prefix) {
4378
- size_t stack_size, guard_size;
4379
- void *stack_addr;
4380
- int rc;
4381
-
4382
- rc = pthread_attr_getguardsize(attr, &guard_size);
4383
- assert(rc == 0);
4384
-
4385
- rc = pthread_attr_getstack(attr, &stack_addr, &stack_size);
4386
- assert(rc == 0);
4387
-
4388
- printf(""Thread %s (id=%lu) stack:\\n"", prefix, thread);
4389
- printf(""\\tstart address\\t= %p\\n"", stack_addr);
4390
- printf(""\\tend address\\t= %p\\n"", stack_addr + stack_size);
4391
- printf(""\\tstack size\\t= %.2f MB\\n"", stack_size / 1024.0 / 1024.0);
4392
- printf(""\\tguard size\\t= %lu B\\n"", guard_size);
4393
- }
4394
-
4395
- void *entry_point(void *arg) {
4396
- pthread_t thread = pthread_self();
4397
-
4398
- int rc;
4399
- pthread_attr_t attr;
4400
- rc = pthread_getattr_np(thread, &attr);
4401
- assert(rc == 0);
4402
-
4403
-
4404
- show_stack(&attr, thread, (char *)arg);
4405
-
4406
-
4407
- return NULL;
4408
- }
4409
-
4410
- int main(int argc, char *argv[]) {
4411
- pthread_t p1, p2;
4412
- int rc;
4413
-
4414
- rc = pthread_create(&p1, NULL, entry_point, ""1"");
4415
- assert(rc == 0);
4416
- rc = pthread_create(&p2, NULL, entry_point, ""2"");
4417
- assert(rc == 0);
4418
-
4419
- entry_point(""main"");
4420
-
4421
- rc = pthread_join(p1, NULL);
4422
- assert(rc == 0);
4423
- rc = pthread_join(p2, NULL);
4424
- assert(rc == 0);
4425
-
4426
- return 0;
4427
- }
4428
- ",1
4429
  "#include <stdio.h>
4430
  #include <stdlib.h>
4431
  #include <string.h>
@@ -4678,42 +4570,6 @@ int main(int argc, char **argv) {
4678
 
4679
  ",0
4680
  "#include <stdio.h>
4681
- #include <pthread.h>
4682
- #include <assert.h>
4683
-
4684
- static volatile int counter = 0;
4685
- pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
4686
-
4687
- void *entry_point(void *arg) {
4688
- printf(""Thread %s: begin\\n"", (char *)arg);
4689
-
4690
- for (int i = 0; i < 1e7; ++i) {
4691
- counter += 1;
4692
- }
4693
-
4694
- printf(""Thread %s: done\\n"", (char *)arg);
4695
- return NULL;
4696
- }
4697
-
4698
- int main(int argc, char *argv[]) {
4699
- pthread_t p1, p2;
4700
- printf(""main: begin with counter = %d\\n"", counter);
4701
- int rc;
4702
- rc = pthread_create(&p1, NULL, entry_point, (void *)""A"");
4703
- assert(rc == 0);
4704
- rc = pthread_create(&p2, NULL, entry_point, (void *)""B"");
4705
- assert(rc == 0);
4706
-
4707
- // join waits for the threads to finish
4708
- rc = pthread_join(p1, NULL);
4709
- assert(rc == 0);
4710
- rc = pthread_join(p2, NULL);
4711
- assert(rc == 0);
4712
- printf(""main: done with counter = %d\\n"", counter);
4713
- return 0;
4714
- }
4715
- ",1
4716
- "#include <stdio.h>
4717
  #include <stdlib.h>
4718
  #include <string.h>
4719
  #include <pthread.h>
 
3985
  exit(EXIT_SUCCESS);
3986
  }
3987
  ",0
3988
+ "#define _GNU_SOURCE /* To get pthread_getattr_np() declaration */
3989
+ #include <assert.h>
3990
  #include <pthread.h>
3991
+ #include <stdio.h>
3992
+ #include <stdlib.h>
3993
+ #include <unistd.h>
3994
 
3995
+ pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
3996
 
3997
+ void show_stack(pthread_attr_t *attr, pthread_t thread, char *prefix) {
3998
+ size_t stack_size, guard_size;
3999
+ void *stack_addr;
4000
+ int rc;
4001
 
4002
+ rc = pthread_attr_getguardsize(attr, &guard_size);
4003
+ assert(rc == 0);
4004
 
4005
+ rc = pthread_attr_getstack(attr, &stack_addr, &stack_size);
4006
+ assert(rc == 0);
4007
 
4008
+ printf(""Thread %s (id=%lu) stack:\\n"", prefix, thread);
4009
+ printf(""\\tstart address\\t= %p\\n"", stack_addr);
4010
+ printf(""\\tend address\\t= %p\\n"", stack_addr + stack_size);
4011
+ printf(""\\tstack size\\t= %.2f MB\\n"", stack_size / 1024.0 / 1024.0);
4012
+ printf(""\\tguard size\\t= %lu B\\n"", guard_size);
4013
+ }
4014
 
4015
+ void *entry_point(void *arg) {
4016
+ pthread_t thread = pthread_self();
4017
+
4018
+ int rc;
4019
+ pthread_attr_t attr;
4020
+ rc = pthread_getattr_np(thread, &attr);
4021
+ assert(rc == 0);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4022
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4023
 
4024
+ show_stack(&attr, thread, (char *)arg);
 
 
4025
 
4026
+
4027
+ return NULL;
4028
  }
4029
 
4030
+ int main(int argc, char *argv[]) {
4031
+ pthread_t p1, p2;
4032
+ int rc;
4033
 
4034
+ rc = pthread_create(&p1, NULL, entry_point, ""1"");
4035
+ assert(rc == 0);
4036
+ rc = pthread_create(&p2, NULL, entry_point, ""2"");
4037
+ assert(rc == 0);
 
 
 
 
 
 
 
 
4038
 
4039
+ entry_point(""main"");
4040
+
4041
+ rc = pthread_join(p1, NULL);
4042
+ assert(rc == 0);
4043
+ rc = pthread_join(p2, NULL);
4044
+ assert(rc == 0);
4045
+
4046
+ return 0;
 
 
4047
  }
4048
  ",1
4049
  "#include <stdio.h>
 
4318
  return 0;
4319
  }
4320
  ",0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4321
  "#include <stdio.h>
4322
  #include <stdlib.h>
4323
  #include <string.h>
 
4570
 
4571
  ",0
4572
  "#include <stdio.h>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4573
  #include <stdlib.h>
4574
  #include <string.h>
4575
  #include <pthread.h>