linux usleep占用cpu,c

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

发布者:admin,转转请注明出处:http://www.yc00.com/news/1687973904a62407.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信