Revision 1226

branches/threaded2merge/tests/threads/msimple/tests_adthread_manager.cpp (revision 1226)
75 75
    data[i].thread_no = i;
76 76
  }
77 77

  
78
  //This starts thread after a unknown delay
78 79
  ad_comm::pthread_manager->create_all(data);
80
  //ASSERT_EQ(0, test_attach_code_value);
81

  
79 82
  //Need to join it
80 83
  ad_comm::pthread_manager->pthread_join_all();
81 84
  ASSERT_EQ(1, test_attach_code_value);
......
86 89
  delete ad_comm::pthread_manager;
87 90
  ad_comm::pthread_manager = 0;
88 91
}
92
static int test_attach_code_value_5threads = 0;
93
pthread_mutex_t test_attach_code_value_5threads_mutex = PTHREAD_MUTEX_INITIALIZER;
94
void* test_attach_code_5threads(void* ptr)
95
{
96
  pthread_mutex_lock(&test_attach_code_value_5threads_mutex);
97
  test_attach_code_value_5threads++;
98
  pthread_mutex_unlock(&test_attach_code_value_5threads_mutex);
99
  return ptr;
100
}
101
TEST_F(tests_adthread_manager, create_all_5threads)
102
{
103
  int nthread = 5;
104
  int ngroups = 1;
105
  ivector ng(1, ngroups);
106
  // number of threads in group 1
107
  ng(1)=nthread;
108
  // create instance of pthread_manager class 
109
  // third argument is number of bytes in the transfer buffer
110
  ad_comm::pthread_manager = new adpthread_manager(ngroups, ng, 32005);
111
  if (ad_comm::pthread_manager == 0)
112
  {
113
    FAIL();
114
  }
115

  
116
  ASSERT_EQ(0, test_attach_code_value_5threads);
117
  ad_comm::pthread_manager->attach_code(test_attach_code_5threads);
118
  ASSERT_EQ(0, test_attach_code_value_5threads);
119

  
120
  new_thread_data* data = new new_thread_data[nthread + 1];
121
  for (int i = 1; i <= nthread; i++)
122
  {
123
    data[i].thread_no = i;
124
  }
125

  
126
  //This starts thread after a unknown delay
127
  ad_comm::pthread_manager->create_all(data);
128
  //ASSERT_EQ(0, test_attach_code_value_5threads);
129

  
130
  //Need to join it
131
  ad_comm::pthread_manager->pthread_join_all();
132
  ASSERT_EQ(5, test_attach_code_value_5threads);
133

  
134
  delete [] data;
135
  data = 0;
136

  
137
  delete ad_comm::pthread_manager;
138
  ad_comm::pthread_manager = 0;
139
}
branches/threaded2merge/tests/GNUmakefile (revision 1226)
5 5
all: $(GTEST_DIR)/gtest-all.o msimple
6 6

  
7 7
ifneq ($(CXX),CC)
8
all: $(GTEST_DIR)/gtest-all.o test-threads gtests
8
all2: $(GTEST_DIR)/gtest-all.o test-threads gtests
9 9
else
10
all:
10
all2:
11 11
endif
12 12

  
13 13
gtests: $(GTEST_DIR)/gtest-all.o

Also available in: Unified diff