C++ threads and classess
C++ threads and classess
我最近一直在开发一个线程程序,很简单,它很有效。我现在想改进它,或者用面向对象的方式重写它。
我正在使用Code::Blocks,正如我所学到的,我将类存储在单独的文件中。在那里,我有.h文件中原型化的函数。我想问的是:我应该从哪里开始线程?我应该在哪里加入他们?在"main.cpp"文件中?如果我存储类和函数,你能提供一个简单的例子来说明如何启动这样的线程吗。在不同的文件中?谢谢
我的类文件
#include "fooCheck.h"
#include <iostream>
fooCheck::fooCheck()
{
std::cout << "blah blah" << std::endl;
std::cout << "ctor"<< std::endl;
}
int fooCheck::fooFS(){ <- I want this to be startred as a thread
some code
return 1;
}
我的头文件
class fooCheck
{
public:
fooCheck();
int fooFS();
private:
};
#endif
和我的main()cpp文件。。。
#include stuff_stuff_stuff
#include "fooCheck.h"
int main()
{
ICMP_check foo_acces_object;
foo_acces_object.fooFS();
}
因此,放置的对象运行良好,并从类中执行函数。我希望类中的函数作为线程启动并执行。我尝试的是:std::thread tt1{foo_check::fooFS()};std::thread tt1{fooFS()};关于如何推进这一进程,有什么建议吗?
我提出了一种运行c++线程的模式,这些线程的生命周期与线程所属的类相同。它基本上是c++类的线程模式,避免了使用c++线程时的一些常见问题。
http://blog.chrisd.info/how-to-run-threads/
相关文章:
- C++核心准则 C35 对于接口类"A base class destructor should be either public and virtual, or protected and nonv
- 为什么C++逐位AND运算符在不同大小的操作数中表现为这样
- 为什么 Clang 不允许"and"作为函数名称?
- 位阵列上的快速AND运算
- 是否可以在 C++03 中定义'move-and-swap idiom'等效项
- BoostPython and CMake
- OpenSSL BIO and SSL_read
- Gurobi GRBModel and GRBmodel in C++
- std::visit and std::variant usage
- SHBrowseForFolder with BIF_BROWSEFORCOMPUTER and SHGetPathFr
- Directx12 and keystrokes
- different between int **arr =new int [ n]; and int a[i][j]?
- C++ getenv and setenv
- Inference pytorch C++ with alexnet and cv::imread image
- Visual Studio 2019 C++ and std::filesystem
- 保证逻辑 AND 表达式中的函数调用
- python ctypes and C++ pointers
- C++ const char with .begin() and .end()
- Threads with Classes and std::packaged_task
- C++ threads and classess