简体   繁体   English

有谁能解释一下这个 boost create_thread 行吗?

[英]any can please explain me this boost create_thread line?

im implementing a github commit on my repo but i see a line and i dont understeand what it means, here is the line:我在我的 repo 上实现了 github 提交,但我看到一行,但我不明白它的含义,这是行:

    threadGroup.create_thread(boost::bind(&BeeKeeper, boost::cref(chainparams)));

i understeand the threadGroup, i know what it its and what its for, i have a function called BeeKeeper() so i guess that is calling that function but i dont get the boost::cref, i dont have a class named chainparams i just have a file called chainparams.h is this just a tag to create the thread with that name or what its for? i understeand the threadGroup, i know what it its and what its for, i have a function called BeeKeeper() so i guess that is calling that function but i dont get the boost::cref, i dont have a class named chainparams i just有一个名为chainparams.h 的文件,这只是创建具有该名称的线程的标签还是它的用途?

Thanks.谢谢。

std::bind.标准::绑定。 boost::bind etc. all bind arguments by value. boost::bind 等都按值绑定 arguments。 To pass a referece, you need to wrap them with a std::reference_wrapper .要传递参考,您需要用std::reference_wrapper包装它们。

std::ref and std::cref (or boost's equivalents) are functions that return those wrappers. std::refstd::cref (或 boost 的等价物)是返回这些包装器的函数。

See If the stored argument arg is of type查看存储的参数 arg 是否属于类型

So you have a variable named chainparams that you pass, by reference, to the thread function.所以你有一个名为chainparams的变量,你通过引用传递给线程function。

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

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