最新消息: USBMI致力于为网友们分享Windows、安卓、IOS等主流手机系统相关的资讯以及评测、同时提供相关教程、应用、软件下载等服务。

linux usleep占用cpu,c

互联网 admin 36浏览 0评论

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

我在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

发布评论

评论列表 (0)

  1. 暂无评论