当前位置: 首页 > news >正文

做推广适合哪些网站英文网站建设需要准备什么

做推广适合哪些网站,英文网站建设需要准备什么,网站建设分期进行怎么入账,郑州中原区网站建设文章目录 #xff08;二#xff09;线程的创建、分离和链接创建线程#xff1a;示例线程的分离#xff08;detach#xff09;和连接#xff08;join#xff09; #xff08;二#xff09;线程的创建、分离和链接 创建线程#xff1a;示例 线程#xff08;Thread二线程的创建、分离和链接创建线程示例线程的分离detach和连接join 二线程的创建、分离和链接 创建线程示例 线程Thread是并发执行的基本单位。在C中std::thread用于创建和管理线程。当你想在线程中执行某个有参数或无参数的函数时你可以将该函数传递给std::thread创建的线程对象以下是一些示例。 示例1传递无参数函数 #include iostream #include threadvoid print_hello() {std::cout Hello from thread!\n; }int main() {// 创建一个 std::thread 类型的对象 t并传递 print_hello作为t构造函数的参数。std::thread t(print_hello);t.join(); // 等待线程结束下一节介绍其作用return 0; }示例2传递带参数函数拷贝 #include iostream #include threadvoid print_number(int num) {std::cout Number: num \n; }int main() {int value 42;std::thread t(print_number, value); // 创建线程并传入参数value 被拷贝给线程 t.join(); // 等待线程结束return 0; }示例3传递带参数函数使用引用或指针 如果你希望在线程中修改传入的参数值可以用std::ref来包装参数以便在创建线程时传递其引用。 #include iostream #include threadvoid modify_number(int num) {num * 2;std::cout Modified number: num \n; }int main() {int value 42;std::thread t(modify_number, std::ref(value)); // 创建线程并传入参数的引用t.join(); // 等待线程结束std::cout Value in main: value \n; // 验证值已被修改return 0; }Modified number: 84 Value in main: 84示例4传递多个参数 你可以传递多个参数给线程函数。 #include iostream #include threadvoid print_info(std::string name, int age) {std::cout Name: name , Age: age \n; }int main() {std::string name Alice;int age 30;std::thread t(print_info, name, age); // 创建线程并传入多个参数t.join(); // 等待线程结束return 0; }示例5传递类的成员函数和实例 你还可以传递类的成员函数和类的实例给线程。 #include iostream #include threadclass Person { public:void say_hello(const std::string greeting) {std::cout greeting from name \n;}std::string name Bob; };int main() {Person person;// 当线程 t 开始执行时它会调用 person 对象的 say_hello 函数并以 Hello 作为参数。std::thread t(Person::say_hello, person, Hello); // 创建线程并传入成员函数和对象指针t.join(); // 等待线程结束return 0; }线程的分离detach和连接join 在C中线程的分离detach和连接join是用于管理线程生命周期的两种主要方式。当创建一个线程时你可以选择让它独立运行即分离或者等待它完成执行即连接。 分离detach 当你调用std::thread::detach()方法时你告诉线程库你不再关心这个线程的结束时间并且你不需要获取它的返回值。线程将在后台独立运行直到其函数返回结束。 示例 #include iostream #include thread #include chrono #include ctime #pragma warning(disable: 4996) void thread_task() { // 阻塞当前线程的执行直到指定的时间间隔(2s)过去 std::this_thread::sleep_for(std::chrono::seconds(2)); auto now std::chrono::system_clock::now(); std::time_t now_c std::chrono::system_clock::to_time_t(now); std::cout Hello from detached thread at std::ctime(now_c) std::endl; } int main() { auto start_time std::chrono::system_clock::now(); std::time_t start_time_c std::chrono::system_clock::to_time_t(start_time); std::cout Main thread starts at std::ctime(start_time_c) std::endl; std::thread t(thread_task); // 创建线程 t.detach(); // 分离线程 // 主线程将不会等待t的结束而是继续执行 std::cout Main thread continues execution without waiting for the detached thread.\n; // 让主线程休眠3s以便观察分离线程的输出 std::this_thread::sleep_for(std::chrono::seconds(3)); auto end_time std::chrono::system_clock::now(); std::time_t end_time_c std::chrono::system_clock::to_time_t(end_time); std::cout Main thread ends at std::ctime(end_time_c) std::endl; return 0; }在这个例子中t线程将开始执行thread_task函数并在调用t.detach()后立即返回主线程。主线程将继续执行而不需要等待t线程的完成。 Main thread starts at Fri May 3 23:02:06 2024Main thread continues execution without waiting for the detached thread. Hello from detached thread at Fri May 3 23:02:08 2024Main thread ends at Fri May 3 23:02:09 2024开始和结束相差3秒。 连接join 当你调用std::thread::join()方法时你告诉线程库你想要等待这个线程完成执行后再继续下去。调用join()的线程将被阻塞直到被连接的线程执行完毕。 示例 #include iostream #include thread #include chrono #include ctime #pragma warning(disable: 4996) void thread_task() { // // 休眠2sstd::this_thread::sleep_for(std::chrono::seconds(2)); auto now std::chrono::system_clock::now(); std::time_t now_c std::chrono::system_clock::to_time_t(now); std::cout Hello from joined thread at std::ctime(now_c) std::endl; } int main() { auto start_time std::chrono::system_clock::now(); std::time_t start_time_c std::chrono::system_clock::to_time_t(start_time); std::cout Main thread starts at std::ctime(start_time_c) std::endl; std::thread t(thread_task); // 创建线程 // 主线程将在这里阻塞等待t的完成 t.join(); std::cout Main thread continues execution after the thread is joined.\n; std::this_thread::sleep_for(std::chrono::seconds(3)); auto end_time std::chrono::system_clock::now(); std::time_t end_time_c std::chrono::system_clock::to_time_t(end_time); std::cout Main thread ends at std::ctime(end_time_c) std::endl; return 0; }在这个例子中t线程将开始执行thread_task函数而主线程在调用t.join()时将阻塞等待t线程完成。当t线程完成后主线程将继续执行。 Main thread starts at Fri May 3 23:11:45 2024Hello from joined thread at Fri May 3 23:11:47 2024Main thread continues execution after the thread is joined. Main thread ends at Fri May 3 23:11:50 2024开始和结束相差5秒。
http://www.tj-hxxt.cn/news/221926.html

相关文章:

  • dede 网站建设模板品牌推广服务
  • 南阳网站排名优化价格logo商标设计
  • 微信公众号怎么进行网站建设电脑系统优化软件
  • 义乌购物网站建设多少钱网络营销做女鞋的网站设计
  • 郏县住房和城乡建设局网站引流推广推广微信hyhyk1效果好
  • 济南手机网站四川省信用建设促进会网站
  • 成都金牛网站建设公司建e室内设计
  • 做网站需要些什么网站创作
  • 网站迁移教材旅游类网站如何做推广
  • 公司域名让做网站的做个网上平台大概要多少钱
  • 自助网站建设系统软件郑州哪家做网站好
  • 支持ipv6网站开发临沂免费模板建站
  • 枣庄学习建设网站培训小语种外贸网站建设
  • 酒店如何做团购网站网站怎么做快捷方式
  • 如何做商业网站网站空间在哪里买
  • 机械毕业设计代做网站c 可以用来做网站吗
  • 做网站推广话术怎么键卖东西的网站
  • 买东西的网站都有哪些聊城哪里可以学网站建设呢
  • 做电商网站需要注意哪些创意100图片欣赏
  • 网站图片一般多大住房和城乡建设部网站
  • 一站式网站建设比较好wordpress 淘客网站
  • 做网站要钱吗广州论坛建站模板
  • 做知识产权服务的网站网页模板下载 可以赚钱吗?
  • 网站建设的技术难点食品类网站模板
  • 网站软件app网络管理系统平台
  • 爱站网ip反域名查询自学网站建设要看什么书
  • 阿里云自助建站教程自适应网站如何做移动适配
  • 武夷山市建设局网站广告模板网站
  • 网站推广渠道怎么做wordpress带会员中心的主题
  • 商城网站流程wordpress qps