TEST_F(TestMemFnPointerSample, All) { Counter counter; CountLater countLater; int expected = 0; EXPECT_EQ(expected, counter.Get()); counter.Increment(); ++expected; EXPECT_EQ(expected, counter.Get()); counter.Decrement(); counter.Decrement(); expected -= 2; EXPECT_EQ(expected, counter.Get()); countLater.Execute(); EXPECT_EQ(expected, counter.Get()); countLater.ExecuteLater(&counter, &Counter::Decrement); EXPECT_EQ(expected, counter.Get()); --expected; for(int i=0; i<2; ++i) { countLater.Execute(); EXPECT_EQ(expected, counter.Get()); } countLater.ExecuteLater(&counter, &Counter::Increment); EXPECT_EQ(expected, counter.Get()); countLater.ExecuteLater(&counter, &Counter::Increment); ++expected; EXPECT_EQ(expected, counter.Get()); }
void* ThreadRunner(void* t){ int k; unsigned int seed=0; for (k=0;k< *(int*)t ;k++){ x.Increment(double(rand_r(&seed))/RAND_MAX,double(rand_r(&seed))/RAND_MAX); } }
void* ThreadRunner(void*) { int k; for (k = 0; k < 100000000; k++) { sem_wait(&semaphore); x.Increment(); sem_post(&semaphore); } }
void* ThreadRunner(void*){ int k; for (k=0;k<100000000;k++){ pthread_mutex_lock(&mutex); x.Increment(); pthread_mutex_unlock(&mutex); } }
void* ThreadRunner(void*){ for(int k = 0 ; k < 100000000 ; k++){ pthread_spin_lock(&m_spinlock); x.Increment(); pthread_spin_unlock(&m_spinlock); } return NULL; }
int main() { Counter i; std::cout << "The value of i is " << i.GetItsVal() << std::endl; i.Increment(); std::cout << "The value of i is " << i.GetItsVal() << std::endl; ++i; std::cout << "The value of i is " << i.GetItsVal() << std::endl; return 0; }
void *ThreadRunner(void*) { //long long each = 300000000/threadNum; for (int k = 0; k < 100000000; ++k) { sem_wait(&sem); x.Increment(); sem_post(&sem); } pthread_exit(NULL); }
void* ThreadRunner(void*){ long int num = total_number_of_points / NUMTHD; double x, y; for(int i = 0; i < num; i++){ x = GetRand(); y = GetRand(); if(x*x + y*y <= 1){ pthread_mutex_lock(&mutex); CT.Increment(); pthread_mutex_unlock(&mutex); } } }
int main() { Counter i; cout << "The value of i is " << i.GetItsVal() << endl; i.Increment(); cout << "The value of i is " << i.GetItsVal() << endl; ++i; cout << "The value of i is " << i.GetItsVal() << endl; Counter a = i++; cout << "The value of a: " << a.GetItsVal()<<endl; ++a; cout << " and a: " << a.GetItsVal() << endl; cout<<"address of i is: "<<&i<<endl; cout<<"address of a is: "<<&a<<endl; return 0; }
void task1(void *pvParameters) { Counter local_counter = Counter(12); Counter *new_counter = new Counter(24); while(1) { Counter *counter = NULL; switch(rand() % 3) { case 0: counter = &local_counter; break; case 1: counter = &static_counter; break; default: counter = new_counter; break; } counter->Increment(); printf("local counter %d static counter %d newly allocated counter %d\r\n", local_counter.getCount(), static_counter.getCount(), new_counter->getCount()); vTaskDelay(100); } }