itas109 / CSerialPort

CSerialPort - lightweight cross-platform serial port library for C++/C/C#/Java/Python/Node.js/Electron
https://blog.csdn.net/itas109/article/details/84282860
Other
740 stars 338 forks source link

read thread high CPU usage on linux(centos 7) #42

Closed itas109 closed 4 years ago

itas109 commented 4 years ago

Describe the bug read thread high CPU usage on linux(centos 7)

To Reproduce compile and run examples\CommNoGui\CSerialPortDemoNoGui run top or htop command

$ htop

CPU[|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||100.0%]   Tasks: 40, 59 thr; 1 running

   PID USER      PRI  NI  VIRT   RES   SHR S CPU% MEM%   TIME+  Command
12165 root     20   0 14980  2884  2684 R 99.1  0.1  0:26.62 ./CSerialPortDemoNoGui

Desktop (please complete the following information):

itas109 commented 4 years ago

use sleep could solve high cpu usage problem. for(;;) is better than while(true)

for(;;)
{
    //do sth.
    usleep(1);
}