C++的自定义线程函数内调用了一个自定义的yield()接口。

在windows上是调用了SwitchToThread来实现的,linux是pthread_yield实现的。

Sleep(0):时间片只能让给优先级相同或更高的线程; 
SwitchToThread():只要有可调度线程,即便优先级较低,也会让其调度。

下面是MSDN上对Sleep函数的描述:

The time interval for which execution is to be suspended, in milliseconds.

A value of zero causes the thread to relinquish the remainder of its time slice to any other thread that is ready to run. If there are no other threads ready to run, the function returns immediately, and the thread continues execution.

Windows XP/2000:  A value of zero causes the thread to relinquish the remainder of its time slice to any other thread of equal priority that is ready to run. If there are no other threads of equal priority ready to run, the function returns immediately, and the thread continues execution. This behavior changed starting with Windows Server 2003.

可以看到,从2003 server开始,Sleep(0)变成了调度所有可调度线程,跟SwitchToThread差不多了。

windows线程yield以及Sleep(0)和SwitchToThread之间的区别的更多相关文章

  1. 第11章 Windows线程池(2)_Win2008及以上的新线程池

    11.2 Win2008以上的新线程池 (1)传统线程池的优缺点: ①传统Windows线程池调用简单,使用方便(有时只需调用一个API即可) ②这种简单也带来负面问题,如接口过于简单,无法更多去控制 ...

  2. 第11章 Windows线程池(1)_传统的Windows线程池

    第11章 Windows线程池 11.1 传统的Windows线程池及API (1)线程池中的几种底层线程 ①可变数量的长任务线程:WT_EXECUTELONGFUNCTION ②Timer线程:调用 ...

  3. windows线程同步

    一.前言 之前在项目中,由于需要使用到多线程,多线程能够提高执行的效率,同时也带来线程同步的问题,故特此总结如下. 二.windows线程同步机制 windows线程同步机制常用的有几种:Event. ...

  4. 【简译】Windows 线程基础

    翻译一篇关于windows线程的文章,原文在此.第一次翻译,如有错误请多指教 =========================================华丽的分割线============== ...

  5. Qt for Windows:Qt 5.4.0 MinGW 静态编译版本制作 (转)

    大致流程: 1.安装Qt(源码版)以及其他必要的环境 2.编译/安装 3.配置 4.使用 ----------正文分割线---------- 1.安装Qt(源码版) 1.1 下载Qt(两个地址二选一即 ...

  6. windows线程池四种情形(win核心读书笔记)

    windows线程池四种情形(win核心读书笔记) Mircosoft从Windows2000引入线程池API,并在Vista后对线程池重新构架,引入新的线程池API.以下所有线程池函数均适用于Vis ...

  7. Windows线程同步(上)

    先介绍一个创建线程的API,参考:https://msdn.microsoft.com/en-us/library/windows/desktop/ms682453%28v=vs.85%29.aspx ...

  8. windows 线程

    在windows中进程只是一个容器,用于装载系统资源,它并不执行代码,它是系统资源分配的最小单元,而在进程中执行代码的是线程,线程是轻量级的进程,是代码执行的最小单位. 从系统的内核角度看,进程是一个 ...

  9. Windows核心编程:第11章 Windows线程池

    Github https://github.com/gongluck/Windows-Core-Program.git //第11章 Windows线程池.cpp: 定义应用程序的入口点. // #i ...

随机推荐

  1. Linux QA

    gitee: https://gitee.com/dhclly/icedog.script.test/blob/master/doc/linux/linux-qa.md 1. linux 中的 ll( ...

  2. 【Edit Distance】cpp

    题目: Given two words word1 and word2, find the minimum number of steps required to convert word1 to w ...

  3. MOTCF 没时间解释了 条件竞争漏洞

    moctf 没时间解释了 条件竞争漏洞 题目链接 条件竞争: 在本题目中,上传文件的时候服务器无条件的接收任何类型的文件,但是你上传之后服务器会给你的文件内容修改为too slow. 比如你上传了一句 ...

  4. vim中插入递增数

    假设生成0-9的递增数 1.插入数字1,yy复制,9p 2.输入命令 let i= | g//s//\=i/ | let i=i+1 3.结果:

  5. mysql数据库增、删、改、查等基本命令

    测试环境:windows7 64位 mysql.exe.Navicat Lite for MySQL.mysql 5.0.18 mysql数据库的基本结构: 数据库(database)包含多个表(ta ...

  6. Halcon18 Mac os 下载

    Halcon18 Mac os 下载地址:http://www.211xun.com/download_page_15.html HALCON 18 是一套机器视觉图像处理库,由一千多个算子以及底层的 ...

  7. 删除 node 【笔记】

    sudo npm uninstall npm -g sudo rm -rf /usr/local/lib/node /usr/local/lib/node_modules /var/db/receip ...

  8. Summary—【base】(CSS)

    CSS知识点 1. CSS又被称为层叠样式表 2. CSS在html中的语法 a) <style> 选择器{键:值;} </style> b) css中最后一个键值可以不写分号 ...

  9. 优化脚本性能 Optimizing Script Performance

    This page gives some general hints for improving script performance on iOS. 此页面提供了一些一般的技巧,提高了在iOS上的脚 ...

  10. php函数总结

    1. isset($var) 变量存在且不为NULL,则返回TRUE 变量不存在或为NULL,则返回FALSE 2. empty($var) 若变量不存在或变量值为"".0.&qu ...