2-pthreads/{array1 → array_reentrant}/main.c RENAMED
@@ -1,38 +1,38 @@
1
  #include <stdio.h>
2
  #include <stdlib.h>
3
  #include <time.h>
4
 
5
  #include "array.h"
6
 
7
  #define MIN_CNT 10
8
  #define MAX_CNT 20
9
 
10
- void print_array(const char* name, const array_t array)
11
  {
12
  printf("%s =", name);
13
  for ( size_t index = 0; index < array_get_count(array); ++index )
14
  printf(" %zu", (size_t)array_get_element(array, index));
15
  putchar('\n');
16
  fflush(stdout);
17
  }
18
 
19
  int main()
20
  {
21
- array_t array1 = array_create(MAX_CNT);
22
- array_t array2 = array_create(MAX_CNT);
23
 
24
  srand( (unsigned int)((unsigned long)time(NULL) + clock()) );
25
  for ( size_t index = 0, count = MIN_CNT + rand() % MAX_CNT; index < count; ++index )
26
  {
27
  array_append( array1, (void*)(10 + (size_t)rand() % 90) );
28
  array_append( array2, (void*)(100 + (size_t)rand() % 900) );
29
  }
30
 
31
  print_array("array1", array1);
32
  print_array("array2", array2);
33
 
34
  array_destroy(array1);
35
  array_destroy(array2);
36
 
37
  return 0;
38
  }
1
  #include <stdio.h>
2
  #include <stdlib.h>
3
  #include <time.h>
4
 
5
  #include "array.h"
6
 
7
  #define MIN_CNT 10
8
  #define MAX_CNT 20
9
 
10
+ void print_array(const char* name, const array_t* array)
11
  {
12
  printf("%s =", name);
13
  for ( size_t index = 0; index < array_get_count(array); ++index )
14
  printf(" %zu", (size_t)array_get_element(array, index));
15
  putchar('\n');
16
  fflush(stdout);
17
  }
18
 
19
  int main()
20
  {
21
+ array_t* array1 = array_create(MAX_CNT);
22
+ array_t* array2 = array_create(MAX_CNT);
23
 
24
  srand( (unsigned int)((unsigned long)time(NULL) + clock()) );
25
  for ( size_t index = 0, count = MIN_CNT + rand() % MAX_CNT; index < count; ++index )
26
  {
27
  array_append( array1, (void*)(10 + (size_t)rand() % 90) );
28
  array_append( array2, (void*)(100 + (size_t)rand() % 900) );
29
  }
30
 
31
  print_array("array1", array1);
32
  print_array("array2", array2);
33
 
34
  array_destroy(array1);
35
  array_destroy(array2);
36
 
37
  return 0;
38
  }