Example #1
0
int
main(void)
{
  printf(1,"testing mutex yield\n");

  mutexA = kthread_mutex_alloc();
  mutexB = kthread_mutex_alloc();

  kthread_mutex_lock(mutexA);

  void* stk1 = malloc(MAX_STACK_SIZE);
  void* stk2 = malloc(MAX_STACK_SIZE);
  int id1 = kthread_create(waitingThread, stk1, MAX_STACK_SIZE);
  int id2 = kthread_create(signalingThread, stk2, MAX_STACK_SIZE);

  kthread_join(id2);
  kthread_mutex_unlock(mutexA);
  kthread_join(id1);


  printf(1,"done\n");

  kthread_exit();
  return 0;
}
Example #2
0
int main(void){
	lock = kthread_mutex_alloc();
	cond = kthread_cond_alloc();
	int i;
	void* stack;// =malloc(4000);
	for(i = 0; i< 20; i++){
		stack =malloc(4000);
		kthread_create(thread1,stack,4000);
	}
	
	for(i = 0; i< 20; i++){
		stack =malloc(4000);
		kthread_create(thread2,stack,4000);
	}
	
	
	exit();
	//return (void *) 0;
}
Example #3
0
mesa_cond_t* mesa_cond_alloc()
{
	printf(1,"%d | [%s] start \n",kthread_id(), __FUNCTION__);

	mesa_cond_t* cv = malloc(sizeof(mesa_cond_t));
	if(cv == 0){
		printf(1,"%d | [%s] malloc cv failed \n",kthread_id(), __FUNCTION__);
		return 0;
	}
	cv->inner_mutex_id = kthread_mutex_alloc();
	cv->numOfThreadsWaiting = 0;

	kthread_mutex_lock(cv->inner_mutex_id);

	if(cv->inner_mutex_id < 0){
		printf(1,"%d | [%s] inner mutex alloc failed \n",kthread_id(), __FUNCTION__);
		return 0;
	}
	printf(1,"%d | [%s] success \n",kthread_id(), __FUNCTION__);

	return cv;
}
Example #4
0
hoare_slots_monitor_t*
hoare_slots_monitor_alloc(){
	hoare_slots_monitor_t* monitor = (hoare_slots_monitor_t*)malloc(sizeof(hoare_slots_monitor_t));
	
	if ((monitor->mutex_id = kthread_mutex_alloc()) <= 0){
		return 0;
	}
	
	if ((monitor->empty = hoare_cond_alloc()) <= 0){
		kthread_mutex_dealloc(monitor->mutex_id);
		return 0;
	}
	
	if ((monitor->hasElements = hoare_cond_alloc()) <= 0){
		kthread_mutex_dealloc(monitor->mutex_id);
		hoare_cond_dealloc(monitor->empty);
		return 0;
	}
	
	monitor->count = 0;
	monitor->doneAddingSlots = 0;
	return monitor;
}