本帖最后由 2009从-1开始 于 2012-10-03 10:49 编辑
[code]
class D
{
};
class A
{
work( D d);
};
class B
{
A a;
// 代码1
for ( int 1 = 0; i < 100; i++ )
{
D d;//d计算得到,有内存的申请释放
m_threadpool.schedule(boost::bind(&A::work,&a,d));
}
// 代码2
vector
by 2009从-1开始 - C/C++ - 2012-10-08 15:49:57 阅读(3451) 回复(8)
本帖最后由 hanzhenlll 于 2012-01-11 11:28 编辑 本人之前也没怎么用过这个线程库..... 主要pthread.h 在c++使用编译错误.... void *类型问题....按照网上的方法 弄成static 后,又不能使用外部方法....惆怅 无奈采用boost库 目前的流程是 while 循环 检查是否满足条件--> 满足就进入下一环节 || 否则继续循环 continue -->检查线程是否开启->如果是则更换线程ID创建新线程 || 否,则开启默认线程 boost::thread thrd12...
[quote]Java类文件[/quote][code]package com.fangzhaoguo.primefinder; public class NativeConcurrentPrimeFinder { static { System.loadLibrary("libJavaNative_ConcurrentPrimeFinder"); } public NativeConcurrentPrimeFinder() { } public native boolean isPrime(final long number); public native int countPrime(final long number); public native int countPrime(final long lower, final long upper)...
[code] mutex::mutex() : m_mutex(0) , m_critical_section(false) { m_critical_section = true; if (m_critical_section) m_mutex = new_critical_section(); else m_mutex = new_mutex(0); } [/code] m_critical_section初始值为false, 进入构造函数又设置为true, (多此一举) 刚设完true, 又来用if判断 (再多此一举) 莫非这代码是机器人写的? 还是暗藏玄机, 实在不解, 衷心向各位请教.
现在有两个操作,一个in,一个out,操作一块公共数据(类似数组)。 要求如果in和out同时处理相同的记录,就串行。如果处理不同的记录就需要支持并行。 我们现在的处理核心逻辑为两个死循环:[code]in: while (true) lock mutex 设置当前row_id_in while (row_id_in == row_id_out) cv_in.wait mutex // 此处死锁 unlock mutex 输入处理 // lock mutex // 对是否死锁无影响 row_id_in置in特有空...
1.boost::thread 库中是否可以产生带有参数的线程,比如现有一个函数:string func(string s),我该如何生成多个线程?且每个线程传入的参数不一样.
2.我用多个线程调用同一个函数,但我想每次调用的函数实现的功能都不一样?比如,线程1和线程2,分别读数据库中的第一条和第二条记录? 我原来想的是在该函数中放一个全局变量,但不知道该如何实现互斥.其代码如下:
#include
看到网上的并发2个线程的程序是这样写的:[code]... boost::thread thread1(boost::bind(&other, port1, port7, addr2)); boost::thread thread2(boost::bind(&other2, port8, port2, addr2)); thread1.join(); thread2.join(); ... [/code]这个并发2个进程要写2个thread的代码,并发100个的话该怎么写呢? 谢谢各位