linux boost多线程特性 线程挂起与唤醒
对于boost线程库,提供了线程根据条件进行挂起唤醒的功能。之前看过使用linux标准线程库做过的一些实验,想知道boost线程库的特性是否也一样。
linux线程的唤醒机制与windows的不同。
在windows下如果执行了线程唤醒操作,该唤醒操作会等待第一个挂起的线程,当系统中有线程挂起的时候,就对其进行唤醒。其生存周期一直到其执行完一次唤醒任务结束。
在linux下,如果执行唤醒操作,该唤醒操作会立刻执行,如果系统中没有挂起的线程,那么该操作就会立刻执行结束,如果有线程在操作执行结束后挂起,则
不会被唤醒。唤醒操作的生存周期是,执行操作的瞬间,有线程挂起就唤醒,没有操作结束。不像windows那样,等待第一个需要的唤醒操作到达。
经过测试,boost线程库在linux上的唤醒操作也遵从上面的特性。测试代码如下:
测试环境:centos ubuntu
boost版本: 1.41.0
#include <stdlib.h>
#include<iostream>
#include<boost/thread/condition.hpp>
#include<boost/thread/locks.hpp>
#include<boost/thread/mutex.hpp>
#include <boost/thread/detail/thread.hpp>
#include <boost/thread/thread_time.hpp>
#include <iostream>
using namespace boost::posix_time;
using namespace std;
boost::mutex token;
boost::condition_variable num_cond;
int thread_amount = 0;
void ThreadOne()
{
boost::mutex::scoped_lock tokenlock( token );
cout << "thread one wait" << endl;
num_cond.wait( tokenlock );
cout << "thread one work" << endl;;
}
void ThreadTwo()
{
boost::mutex::scoped_lock tokenlock( token );
cout << "thread two wait" << endl;
num_cond.wait( tokenlock );
cout << "thread two work" << endl;
}
void Awoke()
{
boost::mutex::scoped_lock tokenlock( token );
cout << "awake now" << endl;
num_cond.notify_one( );
}
/*
*
*/
int main(int argc, char** argv)
{
boost::thread aw(&Awoke);
sleep(1);
boost::thread w(&ThreadOne);
boost::thread
相关文档:
利用dnw及串口终端下载安装linux到开发板时,要先设成Nor Flash 启动,步骤如下:
1) 对Nand Flash进行分区
2) 安装bootloader
3) 安装内核文件
4) 安装文件系统
下载完毕要先拔下usb接线,若不取下来有可能导致在系统复位时,电脑会死机。 ......
1、关于文本编辑器;
文本编辑器有很多,比如图形模式的gedit、kwrite、OpenOffice ... ... ,文本模式下的编辑器有vi、vim(vi的增强版本)和nano ... ... vi和vim是我们在Linux中最常用的编辑器。我们有必要介绍一下vi(vim)最简单的用法,以让Linux入门级用户在最短的时间内学会使用它。
nano 工具和DOS操作系统下的e ......
//获去GateWay
QString GetGateWay()
{
FILE *fp;
char buf[512];
char cmd[128];
char gateway[30];
char *tmp;
strcpy(cmd, "ip route");
fp = popen(cmd, "r");
if(NULL == fp)
{
perror("popen error");
return "";
}
while(fgets(buf, sizeof(buf), fp) != NULL)
{
tmp =buf;
w ......
原文地址:http://i.yoho.cn/logview/11756.html
在网上查找了配置linux配置IP的方法,简单的有下面两种:
最常用的给网卡配置ip的命令为
#ifconfig eth0 192.168.0.1 netmask 255.255.255.0 up
说明:
eth0是第一个网卡,其他依次为eth1,eth*
192.168.0.1是给网卡配置的第一个网卡配置的 ......
系统收到邮件都会保存在“/var/spool/mail/[linux用户名]”文件中。
在linux中输入mail,就进行了收件箱,并显示二十封邮件列表。
此时命令提示符为"&"
unread 标记为未读邮件
h|headers 显示当前的邮件列表
l|list 显示当前支持的命令列表
?|help 显示多个查看邮件列表的命令参数用法
d 删除当前邮件 ......