简体   繁体   English

cmake不使用boost多线程库

[英]cmake not using boost multithreaded libraries

I've set(Boost_USE_MULTITHREADED ON) But it still doesn't use -mt libraries. 我已经set(Boost_USE_MULTITHREADED ON)但是它仍然不使用-mt库。

cmake_minimum_required(VERSION 2.6)
PROJECT(app)
set(Boost_USE_MULTITHREADED ON)
FIND_PACKAGE(Boost COMPONENTS filesystem program_options thread serialization REQUIRED)
ADD_EXECUTABLE(app long_list_of_files)
TARGET_LINK_LIBRARIES(app ${Boost_LIBRARIES})

I can see serialization process is using only one CPU core (100%) and not using others. 我可以看到序列化过程仅使用一个CPU内核(100%),而不使用其他CPU内核。 and also ldd doesn't show -mt libraries 而且ldd不显示-mt

linux-gate.so.1 =>  (0xb781f000)
libboost_filesystem.so.1.42.0 => /usr/lib/libboost_filesystem.so.1.42.0 (0xb77e9000)
libboost_program_options.so.1.42.0 => /usr/lib/libboost_program_options.so.1.42.0 (0xb7795000)
libboost_thread.so.1.42.0 => /usr/lib/libboost_thread.so.1.42.0 (0xb7780000)
libpthread.so.0 => /lib/libpthread.so.0 (0xb7766000)
libboost_serialization.so.1.42.0 => /usr/lib/libboost_serialization.so.1.42.0 (0xb76f3000)
libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0xb7608000)
libm.so.6 => /lib/libm.so.6 (0xb75e2000)
libgcc_s.so.1 => /lib/libgcc_s.so.1 (0xb75c5000)
libc.so.6 => /lib/libc.so.6 (0xb7468000)
libboost_system.so.1.42.0 => /usr/lib/libboost_system.so.1.42.0 (0xb7463000)
librt.so.1 => /lib/librt.so.1 (0xb745a000)
/lib/ld-linux.so.2 (0xb7820000)

Boost Serialization aims at providing thread-safety, but not concurrent serialization via threads. Boost序列化旨在提供线程安全性,而不是通过线程进行并发序列化。

When installing Boost via a package manager, you will often find library aliases in /usr/lib that map a more verbose name of the library to a canonical one. 通过包管理器安装Boost时,通常会在/usr/lib中找到库别名,这些别名将库的更详细的名称映射到规范库。 In the case of Boost, the "tagged" name includes the multi-threading ability via the -mt suffix. 在Boost的情况下,“标记”名称包括通过-mt后缀的多线程功能。

ldd displays only the name used by CMake when it invoked the linker, which is the canonical one and not the verbose one with the *-mt suffix. ldd仅显示CMake调用链接程序时使用的名称,该名称是规范名称,而不是带*-mt后缀的详细名称。 Because your Boost package installation involved the creation of symlinks of the form 因为您的Boost软件包安装涉及创建表单的符号链接

/usr/lib/libboost_thread-mt.so -> libboost_thread.so.1.42.0

you should not need to worry about the wrong libraries being linked. 您无需担心链接错误的库。

In fact, Boost Serialization does not spawn threads by itself, so you should not see an increased number of threads just by using the library. 实际上,Boost序列化本身不会产生线程,因此仅使用该库就不会看到增加的线程数。 Internally, the serialization library uses a mutex to protect the counter of a shared pointer. 在内部,序列化库使用互斥锁来保护共享指针的计数器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM