zoukankan      html  css  js  c++  java
  • C/C++ Sleep(0)

    Sleep(0) 的意义是放弃当前线程执行的时间片,把自身放到等待队列之中。这时其它的线程就会得到时间片进行程序的程序。Sleep(0)能够降低当前线程的执行速 度,比如:现在系统中有100个线程(先假设是线程吧)在执行不同的任务,并且它们执行的优先级都是一样的,并且它们每一次分配的时间片的长度都是一样 的。那么现在当前线程中有一个Sleep(0),那么对于当前线程获得时间片的等待时间延长了1倍,也就是说相当于 200 个时间片之后再得到时间片执行任务。

    标准库中无该函数

    但在某些编译系统中有,在有些系统库中有,要根据你那边的环境而定。
    如:

    linux中有,unsigned int sleep(unsigned int seconds),传入挂起时间,成功返回0,不成功则返回余下的秒数。
    windows系统中有Sleep函数(注意大写),void Sleep(DWORD dwMilliseconds); 提供挂起的毫秒数。

    Sleep就是把自己挂起,结束当前时间片

    例如:

    #include<iostream>
    #include<windows.h>
    using namespace std;
    int main()
    {
    Sleep(3000);//暂停3秒  S要大写
    return 0;
    }

    Use std::this_thread::sleep_for:

    ::::(111605// or whatever::::();

    There is also the complimentary std::this_thread::sleep_until.


    Prior to C++11, C++ had no thread concept and no sleep capability, so your solution was necessarily platform dependent. Here's a snippet that defines a sleep function for Windows or Unix:

    #ifdef#include<windows.h>void(unsigned){Sleepmilliseconds}#else#include<unistd.h>void(unsigned){(*1000// takes microseconds}#endif
    But a much simpler pre-C++11 method is to use boost::this_thread::sleep
  • 相关阅读:
    vue导出Excel表格(纯前端)
    Ubuntu16.04+CUDA8.0+CUNN5.1+caffe+tensorflow+Theano
    python高级特性
    顺序容器
    感知机和支持向量机
    IO库
    字符串、向量、数组、迭代器

    c++函数
    C++语句
  • 原文地址:https://www.cnblogs.com/zhaoxinshanwei/p/4036264.html
Copyright © 2011-2022 走看看