How to give priority to privileged thread in mutex locking?

后端 未结 8 1343
失恋的感觉
失恋的感觉 2020-12-01 02:48

First of all: I am completely a newbie in mutex/multithread programming, so sorry for any error in advance...

I have a program that runs multiple threads. The threads

8条回答
  •  不知归路
    2020-12-01 03:39

    Since thread priorities isn't working for you:

    Create 2 mutexes, a regular lock and a priority lock.

    Regular threads must first lock the normal lock, and then the priority lock. The priority thread only has to lock the priority lock:

    Mutex mLock;
    Mutex mPriLock;
    
    
    doNormal()
    {
       mLock.lock();
       pthread_yield();
       doPriority();
       mLock.unlock();
    }
    
    doPriority()
    {
       mPriLock.lock();
       doStuff();
       mPriLock.unlock();
    }
    

提交回复
热议问题