コード例 #1
0
ファイル: ballotBox.c プロジェクト: TVilaboa/ParseV2
//process the first truck stored in queue and adds the schools from that truck to a tree in order to print them ordenated
void process(node **root){
    truck truck;
    Node *node=delQueue();
    truck=node->Data;
    printf("Truck %d waited %d hours\n",counter/3,counter - truck.hours);
    int i=0;
    if(sizeofqueue()>0){
    for(i;i<500;i++){


     school school=truck.schools[i];

         Node *tmp;
    tmp = search(root, school);
    if (tmp)
    {
        createSchool(&((*root)->data),(*root)->data.code,(*root)->data.cantboxes+1);

    }
    else
    {
        insert(root,school);

    }
    }
}
}
コード例 #2
0
void MyThreadExit(void)
{
	bool flag = false;
	UThread* parentthread = currThreadNode->parent;
	UThread* currChild = currThreadNode->child;
	if (parentthread != NULL)
	{
		UThread* temp = parentthread->child;

		while (temp != NULL)
		{
			if (temp->JoinPresent == 1 && temp != currThreadNode)
			{
				flag = true;
				break;
			}
			temp = temp->sib;
		}

		if ((!flag) && (currThreadNode->JoinPresent == 1))
		{
			delQueue(parentthread);
		}

		if (parentthread->child == currThreadNode)
		{
			parentthread->child = currThreadNode->sib;
		}
		else
		{
			UThread*  temp2 = parentthread->child;
			while (temp2->sib != currThreadNode)
			{
				temp2 = temp2->sib;
			}
			temp2->sib = temp2->sib->sib;
		}
		currThreadNode->parent = NULL;
	}

	while (currChild != NULL)
	{
		currChild->parent = NULL;
		currChild = currChild->sib;
	}

	UThread* temp3 = currThreadNode;
	popQueue();
	
	if (currThreadNode != NULL)
	{
		free(temp3->ctx);
		free(temp3);
		setcontext(currThreadNode->ctx);
	}
}
コード例 #3
0
/// Function to Traverse the Binary tree using Breadth-First Traversal Technique 
void breadthTraversal(struct bt_node *tree)
{
	struct bt_node *t;
	addQueue(tree);
	while ((t=delQueue())!=NULL)
	{
		printf("%d\n",t->data);
		if (t->lchild !=NULL)
			addQueue(t->lchild);
		if (t->rchild !=NULL)
			addQueue(t->rchild);
	}
}
コード例 #4
0
void *teller_1( void *ptr )
{
	usleep(500000);
     while(global_time > 0){
    	 int customer_time;    //individual customer time.
    	 //customer_time = rand() % 12 + 1;
    	 customer_time = rand() % 25 + 1;
    	 //printf("teller_1 : global_time = %d and customer_time = %d min\n", global_time, ((customer_time / 2) + (customer_time %2)) );
    	 usleep( 50000 * customer_time );
    	 delQueue();
    	 printf("This is from Thread_1.\n");
     }
}
コード例 #5
0
int main()
{
     int i=0;
     front=NULL;
     printf(" \n1. Push to Queue");
     printf(" \n2. Pop from Queue");
     printf(" \n3. Display Data of Queue");
     printf(" \n4. Exit\n");
     while(1)
     {
          printf(" \nChoose Option: ");
          scanf("%d",&i);
          switch(i)
          {
                case 1:
                {
                     int value;
                     printf("\nEnter a valueber to push into Queue: ");
                     scanf("%d",&value);
                     push(value);
                     display();
                     break;
                }
                case 2:
                {
                     delQueue();
                     display();
                     break;
                }
                case 3:
                {
                     display();
                     break;
                }
                case 4:
                {
                     exit(0);
                }
                default:
                {
                     printf("\nwrong choice for operation");
                }
          }
     }
}
コード例 #6
0
ファイル: execute-command.c プロジェクト: Chitalia/Projects
void execute_parallel()
{
 int ndpid_array_size = 10;
 int num_ndpid = 0;
 int* ndpid_array = malloc(ndpid_array_size*sizeof(int));
 pid_t pid;




  while (queueSize(NoDependency_rear) > 0) 
    {
       struct queueNode* ptr= delQueue(&NoDependency_front, &NoDependency_rear);
       graphNode* temp = ptr->data;
       pid = fork();
       if (pid == 0)
          {
          execute_command(temp->command, 0);
          exit(1); 
          }
       else if (pid > 0){
          if (num_ndpid == ndpid_array_size){
            ndpid_array_size += 10;
            ndpid_array = realloc(ndpid_array, ndpid_array_size*sizeof(int));
          }
          ndpid_array[num_ndpid] = pid;
          temp->pid = pid;
          num_ndpid++;
          }
     }
  if(queueSize(Dependency_rear) == 0){
    int i;
    for(i = 0; i < num_ndpid; i++){
      waitpid(ndpid_array[i], 0, 0);
    }
    free(ndpid_array);
    return;
  }
 

int dpid_array_size = 10;
int num_dpid = 0;
int* dpid_array = malloc(dpid_array_size*sizeof(int));
bool isInvalid = false;


  while (queueSize(Dependency_rear) > 0)
        {
           struct queueNode* ptr = delQueue(&Dependency_front, &Dependency_rear);
           graphNode* temp = ptr->data;
           int i = 0;
           for (; i < temp->before_index; i++)
               {
                  if (temp->before[i]->pid == -200)
                     {
                     push(&Dependency_front, &Dependency_rear, temp);
                     isInvalid = true;
                     break;                      
                     }

                  if (waitpid(temp->before[i]->pid, 0, WNOHANG) == 0){
                     push(&Dependency_front, &Dependency_rear, temp);
                     isInvalid = true;
                     break;
                  }

               }
           if (isInvalid){
              isInvalid = false; 
              continue;
           }
           pid = fork();
           if (pid == 0)
              {
                execute_command(temp->command, 0);
                exit(1); 
              }
           else if (pid > 0){
                if (num_dpid == dpid_array_size){
                   dpid_array_size += 10;
                   dpid_array = realloc(dpid_array, dpid_array_size*sizeof(int));
                }
              dpid_array[num_dpid] = pid;
              temp->pid = pid;
              num_dpid++;
              }   
        }

    int j = 0;
    for(; j < num_dpid; j++){
      waitpid(dpid_array[j], 0, 0);
    }
    free(dpid_array);
  
    int q;
    for(q = 0; q < num_ndpid; q++){
      waitpid(ndpid_array[q], 0, 0);
    }
    free(ndpid_array);


}