This is my reading notes of "Concurrent Programming on Windows", as I said before, I am quite a newbie on this area, there maybe errors in my understanding and summary, please kindly point them out if there is any.
Monthly Archives: June 2010
TBB Study Notes (2)
tbb::concurrent_vector
和stl::vector相比,tbb::concurrent_vector不支持insert和erase操作,且不保证内存是连续的。因为不支持insert操作,故而无法实现由一个线程进行插入排序,并同时由另一个线程去遍历的场景。TBB中也没有平衡树的支持,估计是因为,插入/删除时的节点移动操作很多,细粒度锁不容易带来更佳性能的原因。
template<typename T, class A>
class concurrent_vector: protected internal::allocator_base<T, A>,
private internal::concurrent_vector_base;
typedef concurrent_vector_base_v3 concurrent_vector_base;
// VC10 defines its own v4 template
struct concurrent_vector_base_v3::segment_t {
void* array;
};
atomic<segment_t*> my_segment;
segment_t my_storage[pointers_per_short_table];
// pointers_per_short_table = 3concurrent_vector_base_v3::concurrent_vector_base_v3():
将指针数组my_storage的元素赋值为NULL, 然后将my_storage赋值给my_segment。
concurrent_vector_base_v3::segment_index_of(index):
即 log2(index|1)
concurrent_vector_base_v3::segment_base (k):
(1 << k & ~1),和2**k(即1<<k)不同,当k为0时,结果为0而不是1
concurrent_vector_base_v3::segment_base_index_of(index):
将index调整为segment内的索引,并返回是第几个segment。
concurrent_vector_base_v3::segment_size(k):
返回第k个segment的大小。1 << k,k==0时应该返回2才对呀?
从逻辑上看,concurrent_vector内部的segments布局如下,总会是2,2,4,8,16,32...
但是实际分配的空间,则可能是16,16,32,64,取决于第一次的reservation, growth 或 assignment操作。如果第一次要求分配10个元素,那么heap上分配的空间是,比10大的最小的2的幂数,即16。
(插图来自http://blogs.msdn.com/b/nativeconcurrency,VC10中的concurrent_vector和TBB中的是同出一脉的。)
concurrent_vector::push_back (item)
调用internal_push_back(sizeof(T), k)去分配一段空间,然后调用internal_loop_guide(ntrails为1)将item拷贝到分配的空间上,最后返回iterator
concurrent_vector_base_v3::internal_push_back(element_size, &index)
使用__TBB_FetchAndIncrementWacquire将m_early_size加1,并将原来的size赋值给tmp和index。调用helper::extend_table_if_necessary(*this, k_old, tmp),在必要时扩展segment table,调用helper::acquire_segment获取一个segment的基地址,计算偏移并返回对应的地址。
libittnotify是一些profiling的函数,在编译时可以打开或关闭。ITT=>Intel Threading Tools。
【紧急更新】SunPinyin-MacOS-2.0.2 (10.5/10.6) Patch 1
非常灰常抱歉,昨天(06/02)发布的2.0.2中发现有一个crash的bug,感谢@fishwang同学的bug report。我刚刚fix了这个bug(#134),并上传了最新的2.0.2的完整安装包,原链接不变。烦请您重新下载安装,对给您带来的不便,实在是万分抱歉 ![]()
发布 SunPinyin-MacOS-2.0.2 (10.5/10.6)
本次更新主要是对2.0.2-beta-1进行了一些修正,加入了“声母简写(z/c/s->zh/ch/sh)”的选项,也加入了全角空格的支持(尚未支持全角小写字母)。
从2.0.2开始,SunPinyin 2 for Mac 全面采用了open-gram的词库和语言模型,因此会导致您的history cache无效,您可以在执行完安装程序之后,手工删除现有的history cache文件($ rm ~/Library/Application\ Support/SunPinyin/history)。另外一个重大的更改是,扩大了wordID的范围,使系统词库+用户词库的理论容量可以达到2^24,您现在可以放心导入比较大的个人词库了。不过这也导致了和2.0/2.0.1的词库格式不相兼容。
正是由于上面两个原因,2.0.2的安装包中,直接包括了lm_sc.t3g.le和pydict_sc.bin.le的二进制数据文件,大家可以直接安装就好。另外,sunpinyin_importer中的系统词表也更新为open-gram的词表了。
对于power的mac用户来说,我们已经解决了大端数据的生成问题,请在安装时下载相应的数据文件 ... 另外,非常抱歉的是,sparkle自动升级的问题还没有来得及解决,请大家不要通过自动升级来安装,而是直接下载pkg包来安装 ...
欢迎大家下载试用 ...