Home > Back-end >  Method: according to the priority level, to line up to join the list
Method: according to the priority level, to line up to join the list

Time:05-14

There is a structure, priority level is divided into one to ten, ten hierarchies
Typedef struct {
string name;//user name
Unint8_t priority;//user preferences
} my_st;

There are two list
ListList
{there is a process with two threads,
Thread 1: per second statement a my_st obj, and myList. Push_back (obj);
Thread 2: iterates myList, whether to have elements that have, according to the priority queue (insert myOkList priority level from high to low) and remove the element from the myList, into the next loop through,
Note: have the lock to ensure exclusive access between the two threads,
}

Question: thread 2 how to implement according to the priority queue (insert myOkList priority level from high to low)?

CodePudding user response:

Have been implemented, with the list: : sort (func)!
  • Related