int MainWork () { int iRetVal = 0; std::vector<SSubscriberRefresh> vectSubscriberList; std::vector<SSubscriberRefresh>::iterator iterSubscr; do { /* загружаем список абонентов */ iRetVal = CreateSubscriberList (&vectSubscriberList); if (iRetVal) { break; } if (vectSubscriberList.size() > 1000) { iRetVal = CreateSessionListFull(g_mmapSessionListFull); if (iRetVal) { g_mmapSessionListFull.clear(); } } /* обходим список абонентов */ iterSubscr = vectSubscriberList.begin(); while (iterSubscr != vectSubscriberList.end()) { /* обрабатыаем учетную запись абонента */ iRetVal = ThreadManager (*iterSubscr); if (iRetVal) { break; } ++iterSubscr; } } while (0); g_mmapSessionListFull.clear(); return iRetVal; }
void run_deadlock_scenario(bool ceiling_priority) { int count = 0; pthread_t P1_ID, P2_ID; /* p1, p2, threads */ p[1] = new Process(1, (float*) &priority[1], PRIORITY_P1); p[2] = new Process(2, (float*) &priority[2], PRIORITY_P2); for (count = 1; count <= 2; count++) { if (ceiling_priority) s[count] = new SemaphoreCeiling(); else s[count] = new SemaphoreInheritance(); s[count]->number = count; } count = 0; Process::SetTable((Process**) p, 2); Semaphore::SetTable((Semaphore**) s, 2); if (ceiling_priority) { /* set the priority ceiling of the mutexes */ /** * P1: locks S1, S2 * P2: locks S2, S2 */ s[1]->pc = PRIORITY_P1; s[2]->pc = PRIORITY_P1; } /* creating a periodic timer to generate pulses every 1 sec. */ Timer t(1, 0); while(1) { pthread_mutex_lock(&mutex); /* release P1 at t = 2 */ if (count == RELEASE_TIME_P1) { priority[1] = PRIORITY_P1; pthread_create(&P1_ID , NULL, P1, NULL); } /* release P2 at t = 0 */ if(count == RELEASE_TIME_P2) { priority[2] = PRIORITY_P2; pthread_create(&P2_ID , NULL, P2, NULL); } /* terminate the program at t = 30 */ if (count == 30) { break; } pthread_mutex_unlock(&mutex); t.Wait(); /* wait for the timer pulse */ cout << endl << "TICK:" << count << "\t"; ThreadManager(); /* to find out and run the active thread */ count++; } }