我们目前正在调查我们程序中可能的未定义行为,该行为由 clang7 UBSan 与 boost 1.69.0 中的 boost::program_option 结合标记。我们已经创建了以下可以编译和运行的工作示例clang++ -std=c++17 -fsanitize=undefined -fno-omit-frame-pointer -lboost_program_options debug.cpp && UBSAN_OPTIONS=print_stacktrace=1 ./a.out
#include <iostream>
#include <boost/program_options.hpp>
namespace po = boost::program_options;
int main() {
std::string test_string = "";
po::options_description desc("test");
desc.add_options()
("string", po::value<std::string>(&test_string))
;
constexpr char *argv[] = {"test", "--string", "test"};
constexpr int argc = sizeof(argv) / sizeof(char*);
po::variables_map vm;
po::store(po::parse_command_line(argc, argv, desc), vm);
std::cerr << "Before notify" << std::endl;
po::notify(vm);
std::cout << "string -> " << test_string << std::endl;
}
Run Code Online (Sandbox Code Playgroud)
我们得到以下输出:
/usr/include/boost/any.hpp:249:17: runtime error: …Run Code Online (Sandbox Code Playgroud) 我使用 python 多处理的方式需要将相对较大的对象返回到主线程。我的例子在这里https://pastebin.com/xs0X9wWu(在pastebin上,因为它包含一个有点大的json blob,因为这个错误需要一个大对象)主要代码如下:
def generate_mutations(original):
for node in original:
yield original
def check(task):
return task
if __name__ == "__main__":
logger = log_to_stderr()
logger.setLevel(logging.DEBUG)
while True:
with Pool(2) as pool:
for result in pool.imap(check, generate_mutations(DATA)):
#for result in map(check, generate_mutations(DATA)):
print("Stopping")
break
print("Loop is done")
print("Processing is done")
Run Code Online (Sandbox Code Playgroud)
发生的情况是,在无限循环的几次迭代之后,池将无法终止并只是挂起(我看到“循环已完成”,但没有看到“处理已完成”)。中止(Ctrl+C)给出以下跟踪(我还在多处理调试日志中添加了):
[DEBUG/MainProcess] created semlock with handle 139668948529152
[DEBUG/MainProcess] created semlock with handle 139668948525056
[DEBUG/MainProcess] created semlock with handle 139668948520960
[DEBUG/MainProcess] created semlock with handle 139668948516864
[DEBUG/MainProcess] created semlock with handle …Run Code Online (Sandbox Code Playgroud)