コード例 #1
0
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());
}
コード例 #2
0
ファイル: base.cpp プロジェクト: Microsheep/NCTU_OS_2015
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);
    }
}
コード例 #3
0
ファイル: sem.cpp プロジェクト: CliffYang/Operating-System
void* ThreadRunner(void*) {
    int k;
    for (k = 0; k < 100000000; k++) {
        sem_wait(&semaphore);
        x.Increment();
        sem_post(&semaphore);
    }
}
コード例 #4
0
ファイル: mutex.cpp プロジェクト: Microsheep/NCTU_OS_2015
void* ThreadRunner(void*){
    int k;
    for (k=0;k<100000000;k++){
        pthread_mutex_lock(&mutex);
        x.Increment();
        pthread_mutex_unlock(&mutex);
    }
}
コード例 #5
0
ファイル: spinlock.cpp プロジェクト: allenwhale/OS
void* ThreadRunner(void*){
    for(int k = 0 ; k < 100000000 ; k++){
        pthread_spin_lock(&m_spinlock);
        x.Increment();
        pthread_spin_unlock(&m_spinlock);
    }
    return NULL;
}
コード例 #6
0
ファイル: 10_8.cpp プロジェクト: MiltonStanley/CPP_In_21_Days
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;
}
コード例 #7
0
ファイル: sem.cpp プロジェクト: easydaniel/OperatingSystem
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);
}
コード例 #8
0
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);
        }
    }
}
コード例 #9
0
ファイル: rator_overloading.cpp プロジェクト: aooaboob/CPP
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;
}
コード例 #10
0
ファイル: simple.cpp プロジェクト: baden/esp-open-rtos
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);
    }
}