I/O Completion Ports-I/O完成端口

I/O Completion Ports 

I/O completion ports are the mechanism by which an application uses a pool of threads that was created when the application was started to process asynchronous I/O requests. These threads are created for the sole purpose of processing I/O requests. Applications that process many concurrent asynchronous I/O requests can do so more quickly and efficiently by using I/O completion ports than by using creating threads at the time of the I/O request.

I/O完成端口是一种机制,通过这个机制,应用程序在启动时会首先创建一个线程池,然后该应用程序使用线程池处理异步I/O请求。这些线程被创建的唯一目的就是用于处理I/O请求。对于处理大量并发异步I/O请求的应用程序,相比在I/O请求发生时才创建线程来说,使用完成端口(s)可以做的更快且更有效率。 

The CreateIoCompletionPort function associates an I/O completion port with one or more file handles. When an asynchronous I/O operation started on a file handle associated with a completion port is completed, an I/O completion packet is queued to the port. This can be used to combine the synchronization point for multiple file handles into a single object. 

CreateIoCompletionPort 函数使一个 I/O 完成端口与一个或更多的文件句柄发生关联。当在与一个完成端口相关的文件句柄上启动的异步 I/O 操作完成时,一个 I/O 完成包就会进入到该完成端口的队列中。对于多个文件句柄来说,这种机制可以用来把多文件句柄的同步点放在单个对象中。(言下之意,如果我们需要对每个句柄文件进行同步,一般而言我们需要多个对象(如: Event 来同步),而我们使用 IO Complete Port 来实现异步操作,我们可以同多个文件相关联,每当一个文件中的异步操作完成,就会把一个 complete package 放到队列中,这样我们就可以使用这个来完成所有文件句柄的同步)

A thread uses the GetQueuedCompletionStatus function to wait for a completion packet to be queued to the completion port, rather than waiting directly for the asynchronous I/O to complete. Threads that block their execution on a completion port are released in last-in-first-out (LIFO) order. This means that when a completion packet is queued to the completion port, the system releases the last thread to block its execution on the port. 

调用 GetQueuedCompletionStatus 函数,某个线程就会等待一个完成包进入到完成端口的队列中,而不是直接等待异步 I/O 请求完成。线程(们)就会阻塞于它们的运行在完成端口(按照后进先出队列顺序的被释放)。这就意味着当一个完成包进入到完成端口的队列中时,系统会释放最近被阻塞在该完成端口的线程。
When a thread calls GetQueuedCompletionStatus, it is associated with the specified completion port until it exits, specifies a different completion port, or frees the completion port. A thread can be associated with at most one completion port.
调用 GetQueuedCompletionStatus ,线程就会将会与某个指定的完成端口建立联系,一直延续其该线程退出,或被指定了不同的完成端口,或者释放了与完成端口的联系。一个线程只能与最多不超过一个的完成端口发生联系。

The most important property of a completion port is the concurrency value. The concurrency value of a completion port is specified when the completion port is created. This value limits the number of runnable threads associated with the completion port. When the total number of runnable threads associated with the completion port reaches the concurrency value, the system blocks the execution of any subsequent threads that specify the completion port until the number of runnable threads associated with the completion port drops below the concurrency value.

完成端口最重要的特性就是并发量。完成端口的并发量可以在创建该完成端口时被指定。该并发量限制了与该完成端口相关联的可运行线程的数目。当与该完成端口相关联的可运行线程的总数目达到了该并发量,系统就会阻塞任何与该完成端口相关联的后续线程的执行,直到与该完成端口相关联的可运行线程数目下降到小于该并发量为止。

The most efficient scenario occurs when there are completion packets waiting in the queue, but no waits can be satisfied because the port has reached its concurrency limit. In this case, when a running thread calls GetQueuedCompletionStatus, it will immediately pick up the queued completion packet. No context switches will occur, because the running thread is continually picking up completion packets and the other threads are unable to run. 

最有效的假想是发生在有完成包在队列中等待,而没有等待被满足,因为此时完成端口达到了其并发量的极限。此时,一个正在运行中的线程调用 GetQueuedCompletionStatus 时,它就会立刻从队列中取走该完成包。这样就不存在着环境的切换,因为该处于运行中的线程就会连续不断地从队列中取走完成包,而其他的线程就不能运行了。

The best value to pick for the concurrency value is the number of CPUs on the machine. If your transaction required a lengthy computation, a larger concurrency value will allow more threads to run. Each transaction will take longer to complete, but more transactions will be processed at the same time. It is easy to experiment with the concurrency value to achieve the best effect for your application. 

对于并发量最好的选值就是您计算机中 CPU 的数目。如果您的事务处理需要一个漫长的计算时间,一个比较大的并发量可以允许更多线程来运行。虽然完成每个事务处理需要花费更长的时间,但更多的事务可以同时被处理。对于应用程序来说,很容易通过测试并发量来获得最好的效果。

The PostQueuedCompletionStatus function allows an application to queue its own special-purpose I/O completion packets to the completion port without starting an asynchronous I/O operation. This is useful for notifying worker threads of external events.

PostQueuedCompletionStatus函数允许应用程序可以针对自定义的专用I/O完成包进行排队,而无需启动一个异步I/O操作。这点对于通知外部事件的工作者线程来说很有用。

The completion port is freed when there are no more references to it. The completion port handle and every file handle associated with the completion port reference the completion port. All the handles must be closed to free the completion port. To close the port handle, call the CloseHandle function.
在没有更多的引用针对某个完成端口时,需要释放该完成端口。该完成端口句柄以及与该完成端口相关联的所有文件句柄都需要被释放。调用 CloseHandle 可以释放完成端口的句柄。
03-08
### MathPix工具介绍 Mathpix Snipping Tool 是一款强大的数学公式识别工具,从最初的原型发展至今已经历了多次迭代和功能增强[^1]。该工具不仅能处理简单的数学表达式,还可以应对复杂的数学模型以及多行公式,并且支持手写公式的识别。 这款应用程序通过不断的科技创新与用户反馈改进,在学术研究和技术领域赢得了良好声誉,成为许多科研人员不可或缺的工作伙伴之一。除了基本的功能外,Mathpix 还提供了多种高级特性来满足不同用户的特定需求。 ### 使用方法 #### 安装与启动 为了使用 Mathpix Snipping Tool ,首先需要下载安装程序并按照提示完成设置过程。一旦成功安装后即可随时调用此应用来进行截图操作。 #### 截取屏幕上的公式图像 当遇到想要转换成 LaTeX 或 AsciiMath 的图片时,只需打开软件界面按下快捷键(默认为 `Ctrl+Alt+M`),此时鼠标指针会变为十字形状以便于选取目标区域;框选所需部分之后松开按键即刻上传至云端服务器等待进一步分析处理。 #### 获取LaTeX代码片段 经过短暂几秒钟的时间延迟过后,所截获的内容将以纯文本形式显示出来供复制粘贴到其他编辑器当中继续编写文档或是分享给他人查看交流之用。 ```python import pyperclip # 假设已获取到LaTeX字符串 stored_in_variable named latex_code pyperclip.copy(latex_code) print("LaTeX code has been copied to clipboard.") ``` 对于希望深入探索更多可能性的用户来说,可以考虑查阅官方提供的扩展插件——如用于解析Markdown文件内的公式标记语法的库 **mathpix-markdown-it** [^2] ——这将进一步提升工作效率和个人体验感。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值