本文整理汇总了C++中semaphore::signal方法的典型用法代码示例。如果您正苦于以下问题:C++ semaphore::signal方法的具体用法?C++ semaphore::signal怎么用?C++ semaphore::signal使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类semaphore
的用法示例。
在下文中一共展示了semaphore::signal方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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);
}
}
示例2: 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;
}
示例3: 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);
}
}
示例4: 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;
}
示例5: 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();
}
}
示例6: 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();
}
示例7:
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;
}
示例8: 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);
}
}