나는 ThreadInfo에 클래스가우선 순위 대기열 C++
class ThreadInfo {
public:
ThreadInfo();
ThreadInfo(const ThreadInfo& orig);
ThreadInfo(int thread_id,int init_time,int sleep_time,int run_time,int priority,int is_critical)
{
this->thread_id=thread_id;
this->is_critical=is_critical;
this->init_time=init_time;
this->priority=priority;
this->run_time=run_time;
this->sleep_time=sleep_time;
}
void set_critical(bool value)
{
is_critical=value;
}
bool get_critical()
{
return is_critical;
}
void set_sleep_time(long value)
{
sleep_time=value;
}
long get_sleep_time(long value)
{
return sleep_time;
}
void set_run_time(long value)
{
sleep_time=value;
}
long get_run_time(long value)
{
return sleep_time;
}
int get_lock_type()
{
return lock_type;
}
void set_lock_type(int lock_type)
{
this->lock_type=lock_type;
}
int get_priority()
{
return priority;
}
void set_priority(int value)
{
this->priority=value;
}
unsigned long int get_thread_id()
{
return thread_id;
}
void set_thread_id(unsigned long int value)
{
this->thread_id=value;
}
virtual ~ThreadInfo();
private:
unsigned long int thread_id;
long init_time;
long sleep_time;
long run_time;
int priority;
bool is_critical;
//1=spin,2=busy,3=semaphore
int lock_type;
};
이며, 클래스
class CompareThread {
public:
bool operator()(ThreadInfo* th1, ThreadInfo* th2)
{
if (th1->get_priority()>th2->get_priority()) return true;
return false;
}
};
다음 난에 요소를 삽입입니다 비교 C에서 다음 우선 순위 큐 ++
priority_queue < ThreadInfo*, vector<ThreadInfo*>, CompareThread > thread_queue;
을 생성 다음 기능,
나는 다음과 같은 함수의 스레드 레지스터를 호출,
int ThreadController::thread_register(pthread_t &t, int priority, bool critical)
{
ThreadInfo ti;
cout<<"t reg:"<<t<<endl;
ti.set_thread_id(t);
ti.set_critical(critical);
ti.set_priority(priority);
ThreadScheduler::Instance()->register_thread(ti);
}
하지만 난이 thread_queue.top를 (호출 할 때 내가 가장 최근의 객체를 가져 큐에 ThreadInfo 객체 일부를 누를 때마다), 여부 우선 순위가 가장 낮은 스레드 객체를 반환해야합니다. 여기에 문제가 있습니까?
으로가는 것이 좋습니다? –
안녕하세요, 코드를 업데이트했습니다. 여기에 요소를 어떻게 밀어 넣었는지 알 수 있습니다. @ JoachimPileborg –
코드의 * lot *을 게시했습니다. * 대부분의 *는 관련이 없습니다. –