易截截图软件、单文件、免安装、纯绿色、仅160KB

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


相关文档:

实战Linux Bluetooth编程(六) L2CAP编程实例

例一:发送Signaling Packet:
Signaling Command是2个Bluetooth实体之间的L2CAP层命令传输。所以得Signaling Command使用CID 0x0001.
多个Command可以在一个C-frame(control frame)中发送。
 如果要直接发送Signaling Command.需要建立SOCK_RAW类型的L2CAP连接Socket。这样才有机会自己填充Command Code,Identi ......

Red Hat Linux 下的GCC安装体会

1.将 arm-linux-gcc 的压缩包解压到tmp目录下
2.将 tmp/usr/local 下的 arm 目录copy 到系统的/usr/local 下
3.执行命令:vi/etc/profile 在path murge的语句断后添加
   pathmurge/usr/local/arm/2.95.3/bin;
4.按ESC键,输入:wq 保存并退出.
5.执行 source /etc/profile
6.建立工作目录mkdir -p/opt/Fr ......

Linux如何查找动态库 转+注


Linux如何查找动态库
 
http://blog.chinaunix.net/u2/60011/showart_1007920.html
 
1.  静态库和动态库的基本概念
静态库,是在可执行程序连接时就已经加入到执行码中,在物理上成为执行程序的一部分;使用静态库编译的程序运行时无需该库文件支持,哪里都可以用,但是生成的可执行文件较大。
动 ......

在linux下 获取,修改网关GateWay的两个函数

//获去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 ......

配置linux 的ip地址

原文地址: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是给网卡配置的第一个网卡配置的 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号