多线程编程之:Linux线程编程
接下来可以在线程运行前后使用“free”命令查看内存的使用情况。以下是运行结果:
$ ./thread_attr
Create tread success
Waiting for thread to finish...
Thread is starting
Waiting for thread to finish...
Thread : job 0 delay = 3
Waiting for thread to finish...
Thread : job 1 delay = 2
Waiting for thread to finish...
Waiting for thread to finish...
Waiting for thread to finish...
Waiting for thread to finish...
Thread : job 2 delay = 9
Thread finished
/* 程序运行之前 */
$ free
total used free shared buffers cached
Mem: 255556 191940 63616 10 5864 61360
-/+ buffers/cache: 124716 130840
Swap: 377488 18352 359136
/* 程序运行之中 */
$ free
total used free shared buffers cached
Mem: 255556 191948 63608 10 5888 61336
-/+ buffers/cache: 124724 130832
Swap: 377488 18352 359136
/* 程序运行之后 */
$ free
total used free shared buffers cached
Mem: 255556 191940 63616 10 5904 61320
-/+ buffers/cache: 124716 130840
Swap: 377488 18352 359136
可以看到,线程在运行结束后就收回了系统资源,并释放内存。
关键词: 多线程编程 Linux pthread_create() 操作系统

加入微信
获取电子行业最新资讯
搜索微信公众号:EEPW
或用微信扫描左侧二维码