admin 管理员组

文章数量: 887021

linux usleep占用cpu,c

我在cent os 5.3和cent os 6.3上编译以下代码:

#include

#include

#include

#include

using namespace std;

pthread_mutex_t _mutex;

pthread_spinlock_t spinlock;

list _task_list;

void * run(void*);

int main()

{

int worker_num = 3;

pthread_t pids[worker_num];

pthread_mutex_init(&_mutex, NULL);

for (int worker_i = 0; worker_i < worker_num; ++worker_i)

{

pthread_create(&(pids[worker_i]), NULL, run, NULL);

}

sleep(14);

}

void *run(void * args)

{

int *recved_info;

long long start;

while (true)

{

pthread_mutex_lock(&_mutex);

if (_task_list.empty())

{

recved_info = 0;

}

else

{

recved

本文标签: linux usleep占用cpu c