当前位置: 首页>>代码示例>>C++>>正文


C++ semaphore类代码示例

本文整理汇总了C++中semaphore的典型用法代码示例。如果您正苦于以下问题:C++ semaphore类的具体用法?C++ semaphore怎么用?C++ semaphore使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了semaphore类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: present

void ste_presentation_surface::present(std::uint32_t image_index,
									   const vk::vk_queue<> &presentation_queue,
									   const semaphore &wait_semaphore) {
	VkSwapchainKHR swapchain = *swap_chain;
	VkSemaphore semaphore_handle = wait_semaphore;

	VkPresentInfoKHR info = {};
	info.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR;
	info.pNext = nullptr;
	info.waitSemaphoreCount = 1;
	info.pWaitSemaphores = &semaphore_handle;
	info.swapchainCount = 1;
	info.pSwapchains = &swapchain;
	info.pImageIndices = &image_index;
	info.pResults = nullptr;

	// Host wait for semaphore
	wait_semaphore.wait_host();

	vk::vk_result res;
	{
		//		std::unique_lock<std::mutex> l(shared_data.swap_chain_guard);
		res = vkQueuePresentKHR(presentation_queue, &info);
	}

	// Raise flag to recreate swap-chain
	if (res != VK_SUCCESS)
		shared_data.swap_chain_optimal_flag.clear(std::memory_order_release);
	if (res != VK_SUCCESS && res != VK_SUBOPTIMAL_KHR && res != VK_ERROR_OUT_OF_DATE_KHR) {
		throw vk::vk_exception(res);
	}
}
开发者ID:ssteinberg,项目名称:ste,代码行数:32,代码来源:ste_presentation_surface.cpp

示例2: vkAcquireNextImageKHR

ste_presentation_surface::acquire_next_image_return_t  ste_presentation_surface::acquire_swapchain_image_impl(
	std::uint64_t timeout_ns,
	semaphore &presentation_image_ready_semaphore,
	const vk::vk_fence<> *presentation_image_ready_fence) const
{
	acquire_next_image_return_t ret;
	vk::vk_result res = vkAcquireNextImageKHR(*presentation_device,
											  *swap_chain,
											  timeout_ns,
											  presentation_image_ready_semaphore ? static_cast<VkSemaphore>(*presentation_image_ready_semaphore) : vk::vk_null_handle,
											  presentation_image_ready_fence ? static_cast<VkFence>(*presentation_image_ready_fence) : vk::vk_null_handle,
											  &ret.image_index);

	// Host signal semaphore
	presentation_image_ready_semaphore.signal_host();

	switch (res.get()) {
	case VK_SUBOPTIMAL_KHR:
		ret.sub_optimal = true;
	case VK_SUCCESS:
		ret.image = &swap_chain_images[ret.image_index];
		break;
	case VK_ERROR_OUT_OF_DATE_KHR:
		ret.sub_optimal = true;
		break;
	default:
		throw vk::vk_exception(res);
	}

	// Furthermore raise flag to recreate swap-chain
	if (res != VK_SUCCESS)
		shared_data.swap_chain_optimal_flag.clear(std::memory_order_release);

	return ret;
}
开发者ID:ssteinberg,项目名称:ste,代码行数:35,代码来源:ste_presentation_surface.cpp

示例3: defined

semaphore::semaphore(const semaphore& other)
{
	i32 value = other.value();
#if defined(CRAP_PLATFORM_WIN)
	_semaphore = CreateSemaphore( 0, value, LMAXIMUMCOUNT, 0 );
#else
	sem_init( &_semaphore, 0, value );
#endif
}
开发者ID:stevenblaster,项目名称:craplib,代码行数:9,代码来源:semaphore.cpp

示例4:

void semaphore::operator=( const semaphore& other )
{
	reset( other.value() );
}
开发者ID:stevenblaster,项目名称:craplib,代码行数:4,代码来源:semaphore.cpp

示例5: barber_action

    void barber_action()
    {
        //funkcja bedaca procesem fryzjera
    
              
	    while(1)
	    {
		 //this_thread::sleep_for(30ms);

		  // cout<<"t\n";
		

         	int cust;


	        customer_ready.wait();
 

		queue_lock.wait();		    
                cust=waiting.front();
                waiting.pop();
		queue_lock.signal();
		barber_ready.signal();



		//cout<<"lol"<<endl;

                do_the_service(cust);
 	    }
            
    }
开发者ID:ozonowicz,项目名称:so-pracownia,代码行数:32,代码来源:barber.cpp

示例6: notifier

    void notifier()
    {
        //time_t begin=time(NULL);
 
 
        while(1)
        {

	  //  cout<<"aa"<<endl;
 
            notify_lock.wait();
 
            while(!notifies.empty())
            {
 
       		pair<int,int> i=notifies.front();     
 
                if(i.first==QUEUE_FULL)
                    cout<<"Kolejka pelna. Nie umieszczono klienta nr "<<i.second<<endl;
                else if(i.first==CUSTOMER_PUT_IN_QUEUE)
                    cout<<"Umieszczono w kolejce klienta nr "<<i.second<<endl;
                else // CUSTOMER_SERVICED
                    cout<<"Obsluzono klienta nr "<<i.second<<endl;
 
       		notifies.pop();
            }
 
            //clear(notifies);
 
            notify_lock.signal();

	     this_thread::sleep_for(30ms);
        }
    }
开发者ID:ozonowicz,项目名称:so-pracownia,代码行数:34,代码来源:barber.cpp

示例7: consume

    void task1()   // producer task
     {
		unsigned int data_token = 0;
		
		while(true) {
		  cout << "\ttask 1 " << " starts some computation at t=" << sc_time_stamp() << endl;
		  consume(t_prod);
          cout << "\ttask 1 " << " dumps data on the circular buffer at t=" << sc_time_stamp() << endl;		  
		  
#ifdef _USING_SEMAPHORE_FOR_PROTECTING_THE_ACCESS
		  write_sem.wait();
#endif		
		  unprotected_cbuff.push(data_token);

#ifdef _USING_SEMAPHORE_FOR_PROTECTING_THE_ACCESS
		  read_sem.post();
#endif				  
		  data_token++;
		  
#ifdef _USING_FLAG_FOR_PROTECTING_THE_ACCESS
		  flag1.set();
#endif		  
  
		}
     }
开发者ID:nandohca,项目名称:kista,代码行数:25,代码来源:two_synch_tasks_semaphore.cpp

示例8: consume

  /**
   * Consume a book by filter.
   *
   * Return number of items consumed.
   */
  unsigned int consume(filter &f) {
    can_read.acquire();
    unsigned int consumed = 0;
    #pragma omp critical
    {
      book *b = find_by_year(f.year);
      if (b != NULL) {
        unsigned int wants_to_consume = f.get_wants_to_consume();
        if (b->count < wants_to_consume)
          consumed = b->count;
        else
          consumed = wants_to_consume;

        b->count -= consumed;
        if (b->empty()) {
          debug << "Deleting " << b->title << endl;
          remove(b);
        }

        f.consume(consumed);
      }
      else {
        can_read.release();
      }
    }
    return consumed;
  }
开发者ID:arturaz,项目名称:concurrent-programming-labaratory-works,代码行数:32,代码来源:SlajusA_L3b.cpp

示例9: function

void function(void){
	for(int i = 0; i < 5; i++){
		counter_mutex.wait();
		for(int j = 0; j < 1000; j++){
			result = result + sin(counter) * tan(counter);
		}
		counter++;
		counter_mutex.signal();
	}
}
开发者ID:chenbk85,项目名称:eThread,代码行数:10,代码来源:test.c

示例10: Make

void Make(int add) {
	int used;
	while(!doneUsing){
		S.acquire();
		if((howMany % 2 == 0 && howMany != used) || (howMany % 3 == 0 && howMany != used)){
			common += add;
			used = howMany;
		}
		S.release();
	}
	
}
开发者ID:miezis,项目名称:ConcurrentProgramming,代码行数:12,代码来源:MiezinasM_L2g.cpp

示例11: barberFunc

unsigned long WINAPI barberFunc(void * data) {
	while (shopOpen) {
		customersWaiting.wait();
		seatsMutex.wait();
		numberOfFreeSeats++;
		barberReady.signal();
		seatsMutex.signal();

		std::cout << "Barber\tI am cutting someones hair" << std::endl;
		Sleep(20);
	}
	return 0;
}
开发者ID:romanchom,项目名称:Parallel2015,代码行数:13,代码来源:barber.cpp

示例12: customer_action

    void customer_action()
    {
        //funkcja bedaca procesem klienta
    time_t begin=time(NULL);
 
 
        while(1)
        { 
            queue_lock.wait();

	   // cout<<waiting.size()<<endl;

	    if( customer_is_to_be_produced())
                if(waiting.size()<=MAX_QUEUE)
                {

		   // cout<<"ff"<<endl;		
			
	            int new_cust=produce_customer();		    

                    waiting.push(new_cust);
 
              	    notify_lock.wait();
                    notifies.push(make_pair(CUSTOMER_PUT_IN_QUEUE, new_cust));
                    notify_lock.signal();
   
                    customer_ready.signal();
                    queue_lock.signal();
                    barber_ready.wait();
 		    
	         //   cout<<"ff"<<endl;
			

                }
 
                else
                {
              	    notify_lock.wait();
                    notifies.push(make_pair(QUEUE_FULL, produce_customer()));
                    notify_lock.signal();
 
                    queue_lock.signal();
                }
	else queue_lock.signal();
 
       // this_thread::sleep_for(30ms);
 
        }
 
    }
开发者ID:ozonowicz,项目名称:so-pracownia,代码行数:50,代码来源:barber.cpp

示例13: do_the_service

    void do_the_service(int customer)
    {
        //funkcja obslugujaca klienta
        //tutaj czekamy losowy kwant czasu
 
        srand(time(NULL));
        int timer=(rand()%3)+1;
        time_t begin_time=time(NULL);
        while(time(NULL)-begin_time<timer);

	notify_lock.wait();
	notifies.push(make_pair(CUSTOMER_SERVICED,customer));
	notify_lock.signal();

    }
开发者ID:ozonowicz,项目名称:so-pracownia,代码行数:15,代码来源:barber.cpp

示例14: Use

void Use(int procNr) {
	int val;
	while(!doneUsing){
		S.acquire();
		if(howMany < 10 && val != common){
			cout << procNr << ") reiksme: " << common << endl;
			val = common;
			howMany++;
		} else if (howMany == 10) {
			doneUsing = true;
		}
		S.release();
	}
	
}
开发者ID:miezis,项目名称:ConcurrentProgramming,代码行数:15,代码来源:MiezinasM_L2g.cpp

示例15: producer_finished

 /**
  * Reduce working producer count by 1.
  */
 void producer_finished() {
   #pragma omp critical
   {
     producer_count -= 1;
     can_read.release();
   }
 }
开发者ID:arturaz,项目名称:concurrent-programming-labaratory-works,代码行数:10,代码来源:SlajusA_L3b.cpp


注:本文中的semaphore类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。