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


C++ mutex::unlock方法代码示例

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


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

示例1: pidController

void pidController()
{
	while( true )
	{
		int flTargetPower = controlRequestedPitch + controlRequestedRoll;
		int frTargetPower = controlRequestedPitch - controlRequestedRoll;
		int rlTargetPower = -controlRequestedPitch + controlRequestedRoll;
		int rrTargetPower = -controlRequestedPitch - controlRequestedRoll;
		
		m.lock();
		if( flTargetPower < 0 )
			flMotorPower = 0;
		else
			flMotorPower = flTargetPower;
		if( frTargetPower < 0 )
			frMotorPower = 0;
		else
			frMotorPower = frTargetPower;
		if( rlTargetPower < 0 )
			rlMotorPower = 0;
		else
			rlMotorPower = rlTargetPower;
		if( rrTargetPower < 0 )
			rrMotorPower = 0;
		else
			rrMotorPower = rrTargetPower;
		m.unlock();
		
		usleep( 50000 ); // 50 ms
	}
}
开发者ID:RellikerV2,项目名称:RPi2-Quadcopter-PiClient,代码行数:31,代码来源:Main.cpp

示例2: sensorUpdater

void sensorUpdater()
{
	SensorManager sm;
	int fixedValues[4];
	int rateValues[4];
	while( true )
	{
		sm.update();
		sm.getValues( fixedValues );
		sm.getRates( rateValues );
		
		m.lock();
		
		yaw = fixedValues[2];
		pitch = fixedValues[1];
		roll = fixedValues[0];
		height = fixedValues[3];
		
		yawRate = rateValues[2];
		pitchRate = rateValues[1];
		rollRate = rateValues[0];
		heightRate = rateValues[3];
		
		m.unlock();
	}
}
开发者ID:RellikerV2,项目名称:RPi2-Quadcopter-PiClient,代码行数:26,代码来源:Main.cpp

示例3: readUnLock

 void readUnLock() {
     lock_guard<mutex> readerCountLock(readerCountLock_);
     readerCount_--;
     if (readerCount_ == 0) {
         resourceLock_.unlock();
     }
 }
开发者ID:new-projects,项目名称:c11,代码行数:7,代码来源:RWLock_writer.cpp

示例4: STAGE_TWO

void STAGE_TWO() //HANDSHAKE STUFF
{
  _mtx.lock() ;
  flag-- ;
  cout << "     NUMBER OF THREADS WORKING: " << flag << endl ;
  _mtx.unlock() ;
}
开发者ID:jcgoodru,项目名称:FastJet_Spring2014,代码行数:7,代码来源:scheduler-example.cpp

示例5: Print

void ThreadMgr::Print(
  const string& fname,
  const string& tag) const
{
  mtxPrint.lock();
  ofstream fo;
  fo.open(fname, std::ios_base::app);

  fo << tag << 
    ": Real threads occupied (out of " << numRealThreads << "):\n";
  for (unsigned t = 0; t < numRealThreads; t++)
  {
    if (realThreads[t])
      fo << t << endl;
  }
  fo << endl;

  fo << "Machine threads overview:\n";
  for (unsigned t = 0; t < numMachineThreads; t++)
  {
    if (machineThreads[t] != -1)
    {
      fo << setw(4) << left << t << machineThreads[t] << endl;
    }
  }
  fo << endl;
  fo.close();
  mtxPrint.unlock();
}
开发者ID:sorenhein,项目名称:dds,代码行数:29,代码来源:ThreadMgr.cpp

示例6: Release

bool ThreadMgr::Release(const int machineId)
{
  mtx.lock();

  bool ret;
  const unsigned m = static_cast<unsigned>(machineId);
  const int r = machineThreads[m];
  const unsigned ru = static_cast<unsigned>(r);

  if (r == -1)
  {
    // Error: Not in use.
    ret = false;
  }
  else if (! realThreads[ru])
  {
    // Error: Refers to a real thread that is not in use.
    ret = false;
  }
  else
  {
    realThreads[ru] = false;
    machineThreads[m] = -1;
    ret = true;
  }

  mtx.unlock();
  return ret;
}
开发者ID:sorenhein,项目名称:dds,代码行数:29,代码来源:ThreadMgr.cpp

示例7: commander

void commander()    //to determin whether the program can stop, and chane the omega used in SOR method
{
	printf("thread Commander begins\n");

	int i, CountAccept = 0;
	double MaxError = 0;
//	omega = 2/(1+Pi/Nx);
	double BoundE = 0;
	bool IsBoundMod = 1;
	int WAIT = 20;
	while(1)
	{
		sleep(WAIT);
		MaxError = 0;

		for(i = 0; i < ThreadNum; i++)
		{
			if(cseg[i].err > MaxError)
				MaxError = cseg[i].err;
		}
		
		m.lock();
		for(i = 0; i < ThreadNum; i++)
			cseg[i].err = 0;
		m.unlock();
//		if(c%8==0)
		printf("err: %e %e\n",MaxError, omega);

		if(MaxError < MAXERR)
		{
//			BoundE = ModifyBound(Point);
			BoundE = 0;
			if(BoundE < BOUNDERR)
			{
				CountAccept++;
				printf("CountAccept %d; BE %e\n", CountAccept, BoundE);
			}
			else
			{
				printf("BE %e\n", BoundE);
			}
			if(CountAccept == 1)
			{
				MAXERR = MAXERR2;    //smaller error
				WAIT = 20;
			}
			if(CountAccept > 5)
			{
				omega = 1;
				break;
			}
			continue;
		}
		CountAccept = 0;
	}
	printf("WAIT ANOTHER 60 SECONDS TO TERMINATE\n");
	sleep(60);
	run = 0;
}
开发者ID:guojingkun,项目名称:SolEleStaPotential,代码行数:59,代码来源:main.cpp

示例8: sequence_read

void sequence_read(int id, int size, int loop, char* fileName){
    char* mem  = (char *) malloc(size);
    FILE* pFile;

    char alterName[80];
    strcpy(alterName, fileName);
    alterName[strlen(fileName)] = id + '0';
    alterName[strlen(fileName) + 1] = 0;

//    cout << alterName << endl;

    pFile = fopen(alterName, "w");
    if(pFile == NULL) {
        cout << "File error." << endl;
        return;
    }
    int minSize = (int)pow(2.0, 30.0);
    int readLoop = size * loop < minSize ? minSize / size : loop;
    for (int i = 0; i < readLoop; ++i) {
        fwrite(mem, sizeof(char), size, pFile);
    }
    fflush(pFile);
    fclose(pFile);

    pFile = fopen(alterName, "r");
    if (pFile == NULL) {
        cout << "File error." << endl;
        return;
    }
    // get the size of file
    fseek(pFile, 0, SEEK_END);
    long fileSize = ftell(pFile);
    rewind(pFile);

    if (loop * size > fileSize) {
        cout << "The file is only " << fileSize << "B, try a loop number smaller than " << fileSize / size << endl;
        return;
    }


    struct timeval start, end;
    gettimeofday(&start, NULL);
    for (int i = 0; i < loop; ++i) {
        fread(mem, sizeof(char), size, pFile);
//        cout << mem << endl;
    }
    gettimeofday(&end, NULL);
    double seconds = end.tv_sec - start.tv_sec + (end.tv_usec - start.tv_usec)/1000000.0;

    if (remove(alterName) != 0) {
        cout << "Error deleting file " << alterName << endl;
    }
    mu.lock();
    durations.push_back(seconds);
    mu.unlock();

    fclose(pFile);
    free(mem);
}
开发者ID:mmmisty,项目名称:benchmarks,代码行数:59,代码来源:disk.cpp

示例9: forJoinThread

void forJoinThread(){ // Will run only in the introducer
    int listenFd = open_socket(port + 1);   //use the port next to UDP as TCP port
    while(true)
    {
        int ret;
        int connFd = listen_socket(listenFd);

        logFile<<"ForJoinThread: one node asking for membership list"<<endl;

        Message income;
        char addr[4];

        read(connFd, &income, sizeof(income));
        
        //if this is normal node: 
        	//if carrier is introducer, send back local list, then add carrier node
        	//else, just add carrier node
        //if this is introducer node:
        	//send back local list. add carrier node. tell everyone carrier node is joining.

        //me is a normal node
        if(!isIntroducer){
        	//if introducer is joining
        	if(income.TTL == 1){
        		//give introducer my local list
        		sendBackLocalList(connFd);
        	}
        	//no matter what is the joining node, join it
        	addMember(income.carrierAdd, income.timeStamp);
        }
        else{	//this node is an introducer

        	//send back local list
        	sendBackLocalList(connFd);
        	
        	//add carrier node
        	addMember(income.carrierAdd, income.timeStamp);
        	
        	usleep( 10*1000 );	//wait to make sure last joined member has enough time to open TCP listening port

        	//tell everyone carrier node is joining
        	membersLock.lock();
        	thread ** broadThreads = new thread*[members.size() ];	//members[0] is introducer itself, members[size-1] is the node just joined
        	for(int i=1; i < members.size() - 1; i++)
        		broadThreads[i] = new thread(broadcastJoin, income, i);
        	for(int i=1; i < members.size() - 1; i++){
        		broadThreads[i]->join();
        		delete broadThreads[i];
        	}
        	delete [] broadThreads;
        	membersLock.unlock();
        }

        close(connFd);
        
        //printMember();
    }
    return;
}
开发者ID:XueweiKent,项目名称:MembershipControlSystem,代码行数:59,代码来源:main.cpp

示例10: end_of_data

bool counter::end_of_data() {
   // Should be const, but then couldn't lock it.
   lock.lock();
   bool end = producer_started and producer_count == 0
              and data_count == 0;
   lock.unlock();
   return end;
}
开发者ID:doitles,项目名称:SpringClasses15,代码行数:8,代码来源:prodconsbuf.cpp

示例11: swap

 void swap(queue_type &q) {
   m_mutex.lock();
   q.swap(m_queue);
   if (m_queue.empty() && sleeping_on_empty) {
     m_empty_conditional.signal();
   }
   m_mutex.unlock();
 }
开发者ID:3upperm2n,项目名称:PowerGraph,代码行数:8,代码来源:blocking_queue.hpp

示例12: ProduceData

    void ProduceData(T data)
    {
        m_mtx.lock();

        m_PrintQueue.push(data);    

        m_mtx.unlock();
    }
开发者ID:nmtgpta,项目名称:C-Practice,代码行数:8,代码来源:main.cpp

示例13: addVideo

VideoDecode* VideoTextureCache::addVideo(const char *path)
{

    VideoDecode* pVideoDecode = (VideoDecode*)m_pVideoDecodes->at(path);
    
    pVideoDecode = new VideoDecode();
    if(pVideoDecode->init(path)) {
        m_pVideoDecodes->insert(path, pVideoDecode);
        
        _threadEnd = false;
        std::thread thread = std::thread([this](void *data){
            VideoDecode *p = (VideoDecode *) data;
            if(p) {
                while(!_threadEnd && p->decode()) {
                    //sleep ?
                    if(_threadEnd)
                        break;
                    
                    mtx.lock();
                    int size = (int)m_pTextures->size();
                    mtx.unlock();
                    while (size > 30) {
                        mtx.lock();
                        size = (int)m_pTextures->size();
                        mtx.unlock();
                    }
                }
            }
            CC_SAFE_RELEASE_NULL(p);
        },pVideoDecode);
        thread.detach();
        pVideoDecode->release();

        s_pAsyncVideoPicQueue = new queue<VideoPic*>();
                
        Director::getInstance()->getScheduler()->schedule(schedule_selector(VideoTextureCache::picToTexture), this, 0, false);
    
        } else {
            CCLOGERROR("CCVideoDecode init error in CCVideoTextureCache");
            return NULL;
        }
    
    pVideoDecode->retain();

    return pVideoDecode;
}
开发者ID:TeamLS,项目名称:6chefs2,代码行数:46,代码来源:VideoTextureCache.cpp

示例14: sendAQFlightCommand

void sendAQFlightCommand(int aqfd) {
    AQFDLock.lock();
    tcflush(aqfd, TCIOFLUSH);
    sendtoAQ32(aqfd, AQ32SendBuffer, AQ32SendBufferLen);
    memset(AQ32SendBuffer, '\0', AQ_SENDBUF_SIZE);
    AQ32SendBufferLen = 0;
    AQFDLock.unlock();
}
开发者ID:g-zhang,项目名称:Dronez-RPi,代码行数:8,代码来源:AutoFlight.cpp

示例15: post

 inline void post() const {
   mut.lock();
   if (waitercount > 0) {
     cond.signal();
   }
   semvalue++;
   mut.unlock();
 }
开发者ID:greeness,项目名称:graphlab_CMU,代码行数:8,代码来源:pthread_tools.hpp


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