• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C++ semaphore类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



在下文中一共展示了semaphore类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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: run

 void run(semaphore & sync_sem)
 {
     running.store(true, boost::memory_order_relaxed);
     sync_sem.post();
     perform();
 }
开发者ID:ELVIS-Project,项目名称:VISIntervalSonifier,代码行数:6,代码来源:callback_interpreter.hpp


示例6: 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


示例7: 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


示例8: 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


示例9: 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


示例10: 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


示例11: 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


示例12: 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


示例13: 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


示例14: 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


示例15: 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


示例16: 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


示例17: customerFunc

unsigned long WINAPI customerFunc(void * data) {
	seatsMutex.wait();
	if (numberOfFreeSeats > 0) {
		numberOfFreeSeats--;
		std::cout << ((int) data) << "\tI have taken a seat." << std::endl;
		customersWaiting.signal();
		seatsMutex.signal();
		barberReady.wait();
		std::cout << ((int)data) << "\tI am having my hair cut. Yay." << std::endl;
	}
	else {
		seatsMutex.signal();
		std::cout << ((int)data) << "\tShop full. Not getting hair cut." << std::endl;
	}

	return 0;
}
开发者ID:romanchom,项目名称:Parallel2015,代码行数:17,代码来源:barber.cpp


示例18:

    pair<int,int> notify_pop()
    {
        //funkcja pobierajaca komunikat ze stosu komunikatow
        //jak nie ma komunikatu, zwracana jest wartosc specjalna
 
 
       	pair <int,int> element;
	notify_lock.wait();
        if(notifies.empty()) element=make_pair(NO_NOTIFIES,0);
        else
	{
 	    element=notifies.front();
	    notifies.pop();
	}
        notify_lock.signal();
 
        return element;
    }
开发者ID:ozonowicz,项目名称:so-pracownia,代码行数:18,代码来源:barber.cpp


示例19: drive

 void drive()
 {
     // do wakeups
     for (unsigned i = 0; i<threads.size(); ++i)
     {
         this_thread::sleep_for(chrono::milliseconds(rand()%100));
         sem.notify();
     }
 }
开发者ID:CCJY,项目名称:coliru,代码行数:9,代码来源:main.cpp


示例20:

     void task2()  // consumer task
     {
		while(true) {
			cout << "Task 2 waits for data at time " << sc_time_stamp() << endl;
#ifdef _USING_FLAG_FOR_PROTECTING_THE_ACCESS			
			wait(flag1);
#endif

#ifdef _USING_SEMAPHORE_FOR_PROTECTING_THE_ACCESS
			read_sem.wait();
#endif
			// KisTA model
		    cout << "task 2 " << "READ " << unprotected_cbuff.pop() << " from circular buffer at t=" << sc_time_stamp() << endl;
			consume(t_cons);
			cout << "task 2 " << "ends some processing at t=" << sc_time_stamp() << endl;
#ifdef _USING_SEMAPHORE_FOR_PROTECTING_THE_ACCESS
			write_sem.post();
#endif		    
		}
     }
开发者ID:nandohca,项目名称:kista,代码行数:20,代码来源:two_synch_tasks_semaphore.cpp



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ sensor_t类代码示例发布时间:2022-05-31
下一篇:
C++ self_type类代码示例发布时间:2022-05-31
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap