Пример #1
0
 void algo8_2_main()
 {
   int i,n;
   FreeList a;
   Space q[N]={NULL}; // q数组为占用块的首地址
   printf("sizeof(WORD)=%u m=%u int(pow(2,m))=%u\n",sizeof(WORD),m,int(pow(2,m)));
   for(i=0;i<=m;i++) // 初始化a
   {
     a[i].nodesize=int(pow(2,i));
     a[i].first=NULL;
   }
   r=a[m].first=new WORD[a[m].nodesize]; // 在最大链表中生成一个结点
   if(r) // 生成结点成功
   {
     r->llink=r->rlink=r; // 初始化该结点
     r->tag=0;
     r->kval=m;
     Print(a);
     PrintUser(q);
     n=100;
     q[0]=AllocBuddy(a,n); // 向a申请100个WORD的内存(实际获得128个WORD)
     printf("申请%d个字后,可利用空间为:\n",n);
     Print(a);
     PrintUser(q);
     n=200;
     q[1]=AllocBuddy(a,n); // 向a申请200个WORD的内存(实际获得256个WORD)
     printf("申请%d个字又",n);
     n=220;
     q[2]=AllocBuddy(a,n); // 向a申请220个WORD的内存(实际获得256个WORD)
     printf("申请%d个字后,可利用空间为:\n",n);
     Print(a);
     PrintUser(q);
     Reclaim(a,q[1]); // 回收q[1],伙伴不空闲
     printf("回收q[1]后,可利用空间为:\n");
     Print(a);
     PrintUser(q);
     Reclaim(a,q[0]); // 回收q[0],伙伴空闲
     printf("回收q[0]后,可利用空间为:\n");
     Print(a);
     PrintUser(q);
     Reclaim(a,q[2]); // 回收q[2],伙伴空闲,生成一个大结点
     printf("回收q[2]后,可利用空间为:\n");
     Print(a);
     PrintUser(q);
   }
   else
     printf("ERROR\n");
 }
Пример #2
0
// test idle scheduling
int main(void){
	int pid,cvarid,lockid;
	TracePrintf(0, "test_temp main:\n");

	LockInit(&lockid);	
	CvarInit(&cvarid);
	
	pid = Fork();
	if(pid==0){
		TracePrintf(0, "child: acquire lock\n");
		Acquire(lockid);
		TracePrintf(0, "child: reclaim cvar\n");
		Reclaim(cvarid);
		TracePrintf(0, "child: exit\n");
		Exit(0);
	}
	else{
		TracePrintf(0, "parent: acquire\n");
		Acquire(lockid);
		TracePrintf(0, "parent: wait\n");
		CvarWait(cvarid,lockid);
		Release(lockid);
	}
	Exit(0);
}
Пример #3
0
bool CActions::ReclaimNearby(int uid){
	NLOG("CActions::ReclaimNearby");
	float3 upos = G->GetUnitPos(uid);
	if(G->Map->CheckFloat3(upos)){
		int* f = new int[100];
		int fc = G->cb->GetFeatures(f,99,upos,700);
		if(fc >0){
			float smallest = 800;
			int fid = 0;
			for(int i = 0; i < fc; i++){
				float3 fpos = G->cb->GetFeaturePos(f[i]);
				float tdist = fpos.distance2D(upos);
				if(tdist < smallest){
					smallest = tdist;
					fid = f[i];
				}
			}
			delete [] f;
			if(fid >0){
				// do stuff
				return Reclaim(uid,fid);
			}
		}else{
			delete [] f;
			return false;
		}
	}
	return false;
}
void TransactionLevelGCManager::Running(const int &thread_id) {

  uint32_t backoff_shifts = 0;

  while (true) {
    auto &txn_manager = concurrency::TransactionManagerFactory::GetInstance();
    auto max_cid = txn_manager.GetMaxCommittedCid();

    PL_ASSERT(max_cid != MAX_CID);

    int reclaimed_count = Reclaim(thread_id, max_cid);

    int unlinked_count = Unlink(thread_id, max_cid);

    if (is_running_ == false) {
      return;
    }

    if (reclaimed_count == 0 && unlinked_count == 0) {
      // sleep at most 0.8192 s
      if (backoff_shifts < 13) {
        ++backoff_shifts;
      }
      uint64_t sleep_duration = 1UL << backoff_shifts;
      sleep_duration *= 100;
      std::this_thread::sleep_for(std::chrono::microseconds(sleep_duration));
    } else {
      backoff_shifts >>= 1;
    }
  }
}
void TransactionLevelGCManager::ClearGarbage(int thread_id) {
  while(!unlink_queues_[thread_id]->IsEmpty() || !local_unlink_queues_[thread_id].empty()) {
    Unlink(thread_id, MAX_CID);
  }

  while(reclaim_maps_[thread_id].size() != 0) {
    Reclaim(thread_id, MAX_CID);
  }

  return;
}
Пример #6
0
int main(int argc, char *argv[]) {
    // Create a single lock that the initial process obtains.
    TracePrintf(TRACE_LEVEL_TESTING_OUTPUT, "Creating the lock.\n");
    int lock_id;
    int parent_cvar_id;
    LockInit(&lock_id);


    int rc;
    // Init with invalid id pointer
    rc = CvarInit((void *) 10);
    TracePrintf(TRACE_LEVEL_TESTING_OUTPUT, "CvarInit w/ invalid pointer: rc = %d\n", rc);

    // Signal with bad id
    rc = CvarSignal(2388);
    TracePrintf(TRACE_LEVEL_TESTING_OUTPUT, "CvarSignal w/ invalid id: rc = %d\n", rc);

    // Broadcast with bad id
    rc = CvarBroadcast(2388);
    TracePrintf(TRACE_LEVEL_TESTING_OUTPUT, "CvarBroadcast w/ invalid id: rc = %d\n", rc);

    // Wait w/ bad cvar id
    rc = CvarWait(lock_id, 1239988);
    TracePrintf(TRACE_LEVEL_TESTING_OUTPUT, "CvarWait w/ invalid cvar id: rc = %d\n", rc);

    // Wait w/ lock I don't own
    rc = CvarWait(lock_id, parent_cvar_id);
    TracePrintf(TRACE_LEVEL_TESTING_OUTPUT, "CvarWait w/ lock I don't own: rc = %d\n", rc);

    // Wait with bad lock id
    rc = CvarWait(1283, parent_cvar_id);
    TracePrintf(TRACE_LEVEL_TESTING_OUTPUT, "CvarWait w/ invalid cvar id: rc = %d\n", rc);

    int child_cvar_id;
    rc = CvarInit(&child_cvar_id);
    TracePrintf(TRACE_LEVEL_TESTING_OUTPUT, "CvarInit w/ %x: rc = %d\n", &child_cvar_id, rc);

    // Signal with no one waiting
    rc = CvarSignal(child_cvar_id);
    TracePrintf(TRACE_LEVEL_TESTING_OUTPUT, "CvarSignal w/ no waiting proc rc = %d\n", rc);

    // Broadcast with no one waiting
    rc = CvarBroadcast(child_cvar_id);
    TracePrintf(TRACE_LEVEL_TESTING_OUTPUT, "CvarBroadcast w/ no waiting proc rc = %d\n", rc);

    rc = CvarInit(&parent_cvar_id);
    TracePrintf(TRACE_LEVEL_TESTING_OUTPUT, "CvarInit w/ %x: rc = %d\n", &parent_cvar_id, rc);

    // The initial process then attempts to acquire the lock it holds. This should return immediately.
    // Spawn 3 processes, each of which waits on the lock.
    int i;
    int n = 3;
    bool is_parent = true;
    for (i = 0; i < n; i++) {
        rc = Fork();

        if (0 == rc) { // Child process
            TracePrintf(TRACE_LEVEL_TESTING_OUTPUT, "I'm a child with PID %d and I WANT the lock!\n",
                 GetPid());

            is_parent = false;

            Acquire(lock_id);

            break;
        }
    }

    // When a spawned process acquires the locks, it delays for a while, then releases it.
    TracePrintf(TRACE_LEVEL_TESTING_OUTPUT, "I'm process %d and I HAVE the lock!\n", GetPid());

    if (!is_parent) {
        TracePrintf(TRACE_LEVEL_TESTING_OUTPUT, "I'm a child w/ PID %d and I'm waiting on my cvar!\n",
            GetPid());
        CvarWait(child_cvar_id, lock_id);
        TracePrintf(TRACE_LEVEL_TESTING_OUTPUT, "I'ma a child w/ PID %d and I've finished waiting!\n",
            GetPid());

        CvarSignal(parent_cvar_id); // signal with proc waiting
    } else {
        Delay(5); // let children start waiting
        Acquire(lock_id);
        TracePrintf(TRACE_LEVEL_TESTING_OUTPUT, "I'm parent w/ PID %d and I'm broadcasting for child  cvar!\n",
            GetPid());

        CvarBroadcast(child_cvar_id); // Broadchat with procs waiting
        TracePrintf(TRACE_LEVEL_TESTING_OUTPUT, "I'm parent w/ PID %d and I'm waiting on my cvar!\n",
            GetPid());
        CvarWait(parent_cvar_id, lock_id);
        TracePrintf(TRACE_LEVEL_TESTING_OUTPUT, "I'm parent w/ PID %d and I've finished waiting!!\n",
            GetPid());
    }
    Release(lock_id);
    
    int status;
    if (is_parent) {
        for (i = 0; i < n; i++) {
            Wait(&status);
        }
        Reclaim(lock_id);
        Reclaim(child_cvar_id);
        Reclaim(parent_cvar_id);
    }

    return 0;
}
Пример #7
0
 void main()
 {
   Space pav,p; /* 空闲块指针 */
   Space v[MAX/e]={NULL}; /* 占用块指针数组(初始化为空) */
   int n;
   printf("结构体WORD为%d个字节\n",sizeof(WORD));
   p=(WORD*)malloc((MAX+2)*sizeof(WORD)); /* 申请大小为MAX*sizeof(WORD)个字节的空间 */
   p->tag=1; /* 设置低址边界,以防查找左右邻块时出错 */
   pav=p+1; /* 可利用空间表的表头 */
   pav->rlink=pav->a.llink=pav; /* 初始化可利用空间(一个整块) */
   pav->tag=0;
   pav->size=MAX;
   p=FootLoc(pav); /* p指向底部域 */
   p->a.uplink=pav;
   p->tag=0;
   (p+1)->tag=1; /* 设置高址边界,以防查找左右邻块时出错 */
   printf("初始化后,可利用空间表为:\n");
   Print(pav);
   n=300;
   v[0]=AllocBoundTag(&pav,n);
   printf("分配%u个存储空间后,可利用空间表为:\n",n);
   Print(pav);
   PrintUser(v);
   n=450;
   v[1]=AllocBoundTag(&pav,n);
   printf("分配%u个存储空间后,pav为:\n",n);
   Print(pav);
   PrintUser(v);
   n=300; /* 分配不成功 */
   v[2]=AllocBoundTag(&pav,n);
   printf("分配%u个存储空间后(不成功),pav为:\n",n);
   Print(pav);
   PrintUser(v);
   n=242; /* 分配整个块(250) */
   v[2]=AllocBoundTag(&pav,n);
   printf("分配%u个存储空间后(整块分配),pav为:\n",n);
   Print(pav);
   PrintUser(v);
   printf("回收v[0](%d)后(当pav空时回收),pav为:\n",v[0]->size);
   Reclaim(&pav,&v[0]); /* pav为空 */
   Print(pav);
   PrintUser(v);
   printf("1按回车键继续");
   getchar();
   printf("回收v[2](%d)后(左右邻区均为占用块),pav为:\n",v[2]->size);
   Reclaim(&pav,&v[2]); /* 左右邻区均为占用块 */
   Print(pav);
   PrintUser(v);
   n=270; /* 查找空间足够大的块 */
   v[0]=AllocBoundTag(&pav,n);
   printf("分配%u个存储空间后(查找空间足够大的块),pav为:\n",n);
   Print(pav);
   PrintUser(v);
   n=30; /* 在当前块上分配 */
   v[2]=AllocBoundTag(&pav,n);
   printf("分配%u个存储空间后(在当前块上分配),pav为:\n",n);
   Print(pav);
   PrintUser(v);
   printf("回收v[1](%d)后(右邻区为空闲块,左邻区为占用块),pav为:\n",v[1]->size);
   Reclaim(&pav,&v[1]); /* 右邻区为空闲块,左邻区为占用块 */
   Print(pav);
   PrintUser(v);
   printf("2按回车键继续");
   getchar();
   printf("回收v[0](%d)后(左邻区为空闲块,右邻区为占用块),pav为:\n",v[0]->size);
   Reclaim(&pav,&v[0]); /* 左邻区为空闲块,右邻区为占用块 */
   Print(pav);
   PrintUser(v);
   printf("回收v[2](%d)后(左右邻区均为空闲块),pav为:\n",v[2]->size);
   Reclaim(&pav,&v[2]); /* 左右邻区均为空闲块 */
   Print(pav);
   PrintUser(v);
 }
Пример #8
0
bool CUNIT::ReclaimBest(bool metal, float radius)
{
	static int features[1000];
	int numfound = ai->cb->GetFeatures(features,1000,pos(),radius);
	float bestscore = 0;
	float myscore = 0;
	float mydistance = 100000;
	int bestfeature = -1;
	if(metal){
		for(int i = 0; i < numfound;i++){
			mydistance = ai->cb->GetFeaturePos(features[i]).distance2D(ai->cb->GetUnitPos(myid));
			myscore = ai->cb->GetFeatureDef(features[i])->metal / (mydistance+1);
			if(ai->tm->ThreatAtThisPoint(ai->cb->GetFeaturePos(features[i])) <= ai->tm->GetAverageThreat()){				
				if(myscore > bestscore){// && !ai->uh->TaskPlanExist(ai->cb->GetFeaturePos(features[i]),ERRORDEF)){			
					// TODO: HACK: See if there are someone on this job already:
					bool found = false;
					for(list<BuilderTracker*>::iterator j = ai->uh->BuilderTrackers.begin(); j != ai->uh->BuilderTrackers.end(); j++){
						if((*j)->customOrderId == (features[i] + MAX_UNITS))
						{
							found = true;
							continue;
						}
					}
					if(found)
						continue;
					bestscore = myscore;
					bestfeature = features[i];
				}
			}
		}
	}
	else{
		for(int i = 0; i < numfound;i++){
			mydistance = ai->cb->GetFeaturePos(features[i]).distance2D(ai->cb->GetUnitPos(myid));
			myscore = ai->cb->GetFeatureDef(features[i])->energy / (mydistance+1);
			if(ai->tm->ThreatAtThisPoint(ai->cb->GetFeaturePos(features[i])) <= ai->tm->GetAverageThreat()){				
				if(myscore > bestscore){// && !ai->uh->TaskPlanExist(ai->cb->GetFeaturePos(features[i]),ERRORDEF)){			
					// TODO: HACK: See if there are someone on this job already:
					bool found = false;
					for(list<BuilderTracker*>::iterator j = ai->uh->BuilderTrackers.begin(); j != ai->uh->BuilderTrackers.end(); j++){
						if((*j)->customOrderId == (features[i] + MAX_UNITS))
						{
							found = true;
							continue;
						}
					}
					if(found)
						continue;
					bestscore = myscore;
					bestfeature = features[i];
				}
			}
		}
	}
	if(bestscore > 0){
		if (Reclaim(bestfeature + MAX_UNITS)) {
		//Reclaim(ai->cb->GetFeaturePos(bestfeature),10);
			//ai->uh->TaskPlanCreate(myid,ai->cb->GetFeaturePos(features[bestfeature]),ERRORDEF);
			return true;
		}
	}
	return false;
}
Пример #9
0
bool CActions::DGunNearby(int uid){
	NLOG("CActions::DGunNearby");
// 	if(G->Ch->dgunning.empty()==false){
// 		if(G->Ch->dgunning.find(uid) != G->Ch->dgunning.end()){
// 			G->L.print("Dgunning failed, dgunning.find() != dgunning.end()");
// 			// This unit is ALREADY dgunning, and is in the middle of doing so, without this check the commander would get confused and
// 			// not dgun anything because it'd be switching between different targets to quickly
// 			return false;
// 		}
// 	}
	const UnitDef* ud = G->cb->GetUnitDef(uid);
	if(ud == 0 ){
		G->L.print("Dgunning failed, ud == 0");
		return false;
	}
	if(G->CanDGun(uid)==false){
		G->L.print("Dgunning failed, canDGun == false");
		return false;
	}
	float3 compos = G->GetUnitPos(uid);
	if(G->Map->CheckFloat3(compos)==false){
		return false;
	}
	int* en = new int[5000];
	int e = G->GetEnemyUnits(en,compos,G->cb->GetUnitMaxRange(uid)*1.3f); // get all enemy units within weapons range atm
	if(e>0){
// 		float best_score = 0;
// 		int best_target = 0;
// 		float tempscore = 0;
		//bool  capture=ud->canCapture;
		//bool commander = false;
		for(int i = 0; i < e; i++){
			if(en[i] < 1) continue;
			const UnitDef* endi = G->GetUnitDef(en[i]);
			if(endi == 0){
				continue;
			}else{
				//if(endi->isCommander == true) continue; // no dgunning enemy commanders!
				// no dgunning enemy commanders is commented out because now if the enemy is a commander the CMD_DGUN is
				// changed to CMD_RECLAIM, allowing the enemy commander to be eliminated without causing a wild goose chase of
				// building dgunned building dgunned, commander in the way of building dgunned, BANG, both commanders bye bye
				if((endi->type == string("Fighter"))&&(endi->type == string("Bomber"))) continue; // attempting to dgun an aircraft without predictive dgunning leads to a goose chase
				int k = en[i];
				delete [] en;
				if(endi->isCommander){
					return Reclaim(uid,k);
				}else{
					return DGun(uid,k);
				}
// 				float3 enpos = G->GetUnitPos(en[i]);
// 				if(G->Map->CheckFloat3(enpos)) continue;
// 				tempscore = G->GetTargettingWeight(ud->name,endi->name);
// 				if(endi->weapons.empty() == false){
// 					capture = false;
// 				}
// // 				if(endi->canKamikaze == true){
// // 					capture = false;
// // 				}
// 				tempscore *= 2;
// 				tempscore = tempscore / compos.distance2D(enpos);
// 				if(tempscore > best_score){
// 					best_score = tempscore;
// 					best_target = en[i];
// 					if(!commander){
// 						commander = endi->isCommander;
// 					}
// 				}
// 				tempscore = 0;
			}
		}
// 		delete [] en;
// 		if(best_target < 1){
// 			G->L.print("Dgunning failed, best_target < 1");
// 			return false;
// 		}
// 		if(commander==true){
// 			if(G->cb->GetUnitHealth(uid)/ud->buildSpeed > G->cb->GetUnitHealth(best_target)/ud->buildSpeed){
// 				;
// 			}else{
// 				return Retreat(uid);
// 			}
// 		}else{
// 			if(capture == false){
// 				return DGun(uid,best_target);
// 			}else{
// 				return Capture(uid,best_target);
// 			}
// 		}
		//G->Manufacturer->UnitDamaged(*aa,99,99,UpVector,true);*/
	}
	delete [] en;
	return false;
}
Пример #10
0
int main(int argc, char* argv[]){
	
	// test 1 : pipe, lock and cvar
	int lock_id, cvar_id, pipe_id;
	int pid,status;
	int condition=0;
	char *test = "Yalnix Works";
	char *buffer = (char*)malloc(1024);

	TracePrintf(1, "init main: test pipe, lock, cvar.\n");
	LockInit(&lock_id);
	CvarInit(&cvar_id);
	PipeInit(&pipe_id);
	TracePrintf(1, "init main: Lockid %d.\n", lock_id);
	TracePrintf(1, "init main: Cvarid %d.\n", cvar_id);
	TracePrintf(1, "init main: Pipeid %d.\n", pipe_id);

	
	pid = Fork();
	if (pid == 0) {	
			TracePrintf(1,"init main: child \n");
			Acquire(lock_id);
			TracePrintf(1,"init main: child acquire the lock\n");
			condition=1;
			TracePrintf(1,"init main: child condition %d\n",condition);
			PipeWrite(pipe_id, &condition,sizeof(int));
			TracePrintf(1,"init main: child change the condition and write it to pipe\n");
			TracePrintf(1,"init main: child cvar signal\n");
			CvarSignal(cvar_id);
			Release(lock_id);
			TracePrintf(1,"init main: child write to pipe: %s\n",test);
			PipeWrite(pipe_id,test,20);
			TracePrintf(1,"init main: child release the lock\n");
			Exit(0);

	}
	else{
		TracePrintf(1,"init main: parent\n");
		Acquire(lock_id);
		TracePrintf(1,"init main: parent acquire the lock\n");
		while(!condition){
			TracePrintf(1,"init main: parent cvar wait, condition %d\n",condition);
			CvarWait(cvar_id,lock_id);
			PipeRead(pipe_id,&condition,sizeof(int));
			TracePrintf(1,"init main: parent read the condition from pipe, condition %d\n",condition);
		}
		TracePrintf(1,"init main: parent wake up\n");
		Release(lock_id);
		TracePrintf(1,"init main: parent release the lock\n");		
		PipeRead(pipe_id,buffer,20);
		TracePrintf(1,"init main: parent read from pipe: %s\n",buffer);
		
	}
	
	Reclaim(lock_id);
	Reclaim(cvar_id);
	Reclaim(pipe_id);
	Exit(0);
	
 
}
Пример #11
0
 void main()
 {
   Space pav,p; // 空闲块指针
   Space v[MAX/e]={NULL}; // 占用块指针数组(初始化为空)
   int n;
   printf("结构体WORD为%d个字节\n",sizeof(WORD));
   p=new WORD[MAX+2]; // 申请大小为MAX*sizeof(WORD)个字节的空间
   p->tag=1; // 设置低址边界,以防查找左右邻块时出错
   pav=p+1; // 可利用空间表的表头
   pav->rlink=pav->llink=pav; // 初始化可利用空间(一个整块)
   pav->tag=0;
   pav->size=MAX;
   p=FootLoc(pav); // p指向底部域
   p->uplink=pav;
   p->tag=0;
   (p+1)->tag=1; // 设置高址边界,以防查找左右邻块时出错
   printf("初始化后,可利用空间表为:\n");
   Print(pav);
   n=300;
   v[0]=AllocBoundTag(pav,n);
   printf("分配%u个存储空间后,可利用空间表为:\n",n);
   Print(pav);
   PrintUser(v);
   n=450;
   v[1]=AllocBoundTag(pav,n);
   printf("分配%u个存储空间后,pav为:\n",n);
   Print(pav);
   PrintUser(v);
   n=300; // 分配不成功
   v[2]=AllocBoundTag(pav,n);
   printf("分配%u个存储空间后(不成功),pav为:\n",n);
   Print(pav);
   PrintUser(v);
   n=242; // 分配整个块(250)
   v[2]=AllocBoundTag(pav,n);
   printf("分配%u个存储空间后(整块分配),pav为:\n",n);
   Print(pav);
   PrintUser(v);
   printf("回收v[0](%d)后(当pav空时回收),pav为:\n",v[0]->size);
   Reclaim(pav,v[0]); // pav为空
   Print(pav);
   PrintUser(v);
   printf("1按回车键继续");
   getchar();
   printf("回收v[2](%d)后(左右邻区均为占用块),pav为:\n",v[2]->size);
   Reclaim(pav,v[2]); // 左右邻区均为占用块
   Print(pav);
   PrintUser(v);
   n=270; // 查找空间足够大的块
   v[0]=AllocBoundTag(pav,n);
   printf("分配%u个存储空间后(查找空间足够大的块),pav为:\n",n);
   Print(pav);
   PrintUser(v);
   n=30; // 在当前块上分配
   v[2]=AllocBoundTag(pav,n);
   printf("分配%u个存储空间后(在当前块上分配),pav为:\n",n);
   Print(pav);
   PrintUser(v);
   printf("回收v[1](%d)后(右邻区为空闲块,左邻区为占用块),pav为:\n",v[1]->size);
   Reclaim(pav,v[1]); // 右邻区为空闲块,左邻区为占用块
   Print(pav);
   PrintUser(v);
   printf("2按回车键继续");
   getchar();
   printf("回收v[0](%d)后(左邻区为空闲块,右邻区为占用块),pav为:\n",v[0]->size);
   Reclaim(pav,v[0]); // 左邻区为空闲块,右邻区为占用块
   Print(pav);
   PrintUser(v);
   printf("回收v[2](%d)后(左右邻区均为空闲块),pav为:\n",v[2]->size);
   Reclaim(pav,v[2]); // 左右邻区均为空闲块
   Print(pav);
   PrintUser(v);
 }
Пример #12
0
int main(int argc, char **argv)
{
	int pid, i, j, ret;
	int exit_status;
	char *exec_argv[] = { "haha", NULL };
	int *a = (int *)calloc(3, sizeof(int));
	int num_a = 100;
	char *str;
	unsigned int delay_ticks = 2;
	char buf[2 * TERMINAL_MAX_LINE + 2];
	char pipe_buf[1025];
	int pipe_fd;
	int lock_fd;
	int cvar_fd;

#ifdef SWAP_TEST
	free(a);
	a = (void *)calloc(num_a, PAGESIZE);
	if (a == NULL)
		goto loop;

	if (Fork() == 0) {
		while (1) {
			Delay(2);
			a[0] = 1000;
			TtyPrintf(CONSOLE, "pid = %u, a[0] = %u\n", GetPid(), a[0]);
		}
	}
	for (i = 0; i < num_a * PAGESIZE / sizeof(int); i += (PAGESIZE / sizeof(int)))
		a[i] = 100;

	if (Fork() == 0) {
		while (1) {
			Delay(2);
			a[0] = 2000;
			TtyPrintf(CONSOLE, "pid = %u, a[0] = %u\n", GetPid(), a[0]);
		}
	}
	for (i = 0; i < num_a * PAGESIZE / sizeof(int); i += (PAGESIZE / sizeof(int)))
		a[i] = 100;

	if (Fork() == 0) {
		while (1) {
			Delay(2);
			a[0] = 3000;
			TtyPrintf(CONSOLE, "pid = %u, a[0] = %u\n", GetPid(), a[0]);
		}
	}
	for (i = 0; i < num_a * PAGESIZE / sizeof(int); i += (PAGESIZE / sizeof(int)))
		a[i] = 100;

	if (Fork() == 0) {
		while (1) {
			Delay(2);
			a[0] = 4000;
			TtyPrintf(CONSOLE, "pid = %u, a[0] = %u\n", GetPid(), a[0]);
		}
	}
	for (i = 0; i < num_a * PAGESIZE / sizeof(int); i += (PAGESIZE / sizeof(int)))
		a[i] = 100;

	if (Fork() == 0) {
		while (1) {
			Delay(2);
			a[0] = 5000;
			TtyPrintf(CONSOLE, "pid = %u, a[0] = %u\n", GetPid(), a[0]);
		}
	}
	for (i = 0; i < num_a * PAGESIZE / sizeof(int); i += (PAGESIZE / sizeof(int)))
		a[i] = 100;
#endif

#ifdef PIPE_TEST
	ret = PipeInit(&pipe_fd);
	pid = Fork();
	bzero(pipe_buf, sizeof(pipe_buf));
	if (pid != ERROR && !pid) {
		TtyPrintf(CONSOLE, "pipe_fd = %u\n", pipe_fd);
		j = 0;
		Delay(1);
		while (1) {
			for (i = 0; i < sizeof(pipe_buf); i++)
				pipe_buf[i] = (j % 26) + 'a';
			TtyPrintf(CONSOLE, ">>>>>>>>>>> write pipe\n");
			ret = PipeWrite(pipe_fd, pipe_buf, sizeof(pipe_buf));
			TtyPrintf(CONSOLE, "write pipe ret = %d, pid = %u\n", ret, GetPid());
			j++;
		}
		Exit(0);
	}
	while (1) {
		bzero(pipe_buf, sizeof(pipe_buf));
		TtyPrintf(CONSOLE, ">>>>>>>>>>> read pipe\n");
		ret = PipeRead(pipe_fd, pipe_buf, sizeof(pipe_buf) - 7);
		TtyPrintf(CONSOLE, "<<<<<<<<<<< read pipe ret = %d, pid = %u, %s\n", ret, GetPid(), pipe_buf);
	}
	Reclaim(pipe_fd);
#endif

#ifdef CVAR_TEST
	ret = LockInit(&lock_fd);
	ret = CvarInit(&cvar_fd);
	pid = Custom0(0, 0, 0, 0);
	if (pid != ERROR && !pid) {
		Acquire(lock_fd);
		while (!condition)
			CvarWait(cvar_fd, lock_fd);
		Delay(2);
		Release(lock_fd);
		Exit(7);
	}
	Acquire(lock_fd);
	condition = 1;
	CvarSignal(cvar_fd);
	Release(lock_fd);
	ret = Reclaim(lock_fd);
	if (ret)
		Exit(-1);
#endif

#ifdef TTY_TEST
	for (i = 0; i < sizeof(buf) - 1; i++)
		buf[i] = '9';
	buf[i] = '\0';
	TtyPrintf(CONSOLE, buf);
	TtyPrintf(CONSOLE, "\n");

	a[0] = 10;
	a[2] = 100;

	TtyPrintf(CONSOLE, "Enter somthing:\n");
	bzero(buf, sizeof(buf));
	ret = TtyRead(CONSOLE, buf, sizeof(buf));
	TtyPrintf(CONSOLE, "You just entered: %s (len = %d)\n", buf, ret);
#endif

#ifdef COW_TEST
	if (argc == 2)
		delay_ticks = atoi(argv[1]);

	pid = Fork();
	if (pid == ERROR) {
		Delay(2);
		return ERROR;
	} else if (!pid) {
		GetPid();
		delay_ticks = 5;

		TtyPrintf(CONSOLE, " delay_ticks = %u, pid = %u\n", delay_ticks, GetPid());
		pid = Fork();
		if (pid != ERROR && !pid) {
			GetPid();
			delay_ticks = 8;
			TtyPrintf(CONSOLE, " delay_ticks = %u, pid = %u\n", delay_ticks, GetPid());
			Delay(delay_ticks);
			Exec("exec_test", exec_argv);
		}
		pid = Wait(&exit_status);
		TtyPrintf(CONSOLE, " delay_ticks = %u, pid = %u\n", delay_ticks, GetPid());
		TtyPrintf(CONSOLE, " wait child = %u, status = %d\n", pid, exit_status);
		Delay(delay_ticks);
		Exit(10);
	}

	pid = Fork();
	if (pid != ERROR && !pid) {
		incursive_func(0);
		GetPid();
		delay_ticks = 9;
		TtyPrintf(CONSOLE, " delay_ticks = %u, pid = %u\n", delay_ticks, GetPid());
		Delay(delay_ticks);
		Exit(100);
	}

	TtyPrintf(CONSOLE, " delay_ticks = %u, pid = %u\n", delay_ticks, GetPid());

	Delay(delay_ticks);
	GetPid();
	Wait(&exit_status);
	Wait(&exit_status);
	GetPid();
#endif

loop:
	while (1)
		Delay(delay_ticks);

	return 0;
}