Revision 1227 branches/threaded2merge/tests/threads/msimple/tests_adthread_manager.cpp

tests_adthread_manager.cpp (revision 1227)
137 137
  delete ad_comm::pthread_manager;
138 138
  ad_comm::pthread_manager = 0;
139 139
}
140
static int lflag = 0;
141
pthread_mutex_t lflag_mutex = PTHREAD_MUTEX_INITIALIZER;
142
void* test_read_lock_buffer(void* ptr)
143
{
144
  //ad_comm::pthread_manager->write_lock_buffer(0);
145
  //ad_comm::pthread_manager->write_unlock_buffer(0);
146
  pthread_mutex_lock(&lflag_mutex);
147
  lflag++;
148
  pthread_mutex_unlock(&lflag_mutex);
149
  return ptr;
150
}
151
TEST_F(tests_adthread_manager, read_lock_buffer)
152
{
153
  const int nthread = 5;
154
  const int ngroups = 1;
155
  ivector ng(1, ngroups);
156
  // number of threads in group 1
157
  ng(1)=nthread;
158
  // create instance of pthread_manager class 
159
  // third argument is number of bytes in the transfer buffer
160
  ad_comm::pthread_manager = new adpthread_manager(ngroups, ng, 32005);
161
  if (ad_comm::pthread_manager == 0)
162
  {
163
    FAIL();
164
  }
165

  
166
  ad_comm::pthread_manager->attach_code(test_read_lock_buffer);
167

  
168
  new_thread_data data[nthread + 1];
169
  for (int i = 0; i <= nthread; i++)
170
  {
171
    data[i].thread_no = i;
172
  }
173

  
174
/*
175
  for (int i = 1; i <= nthread; i++)
176
  {
177
    ad_comm::pthread_manager->write_lock_buffer(i);
178
    ad_comm::pthread_manager->send_int(1, i);
179
    ad_comm::pthread_manager->write_unlock_buffer(i);
180
  }
181
*/
182

  
183
  ASSERT_EQ(0, lflag);
184
  //This starts thread after a unknown delay
185
  ad_comm::pthread_manager->create_all(&data);
186
  //Need to join it
187
  ad_comm::pthread_manager->pthread_join_all();
188
  ASSERT_EQ(5, lflag);
189

  
190
  delete ad_comm::pthread_manager;
191
  ad_comm::pthread_manager = 0;
192
}

Also available in: Unified diff