异步写入套接字线程是否安全? [英] Are Asynchronous writes to a socket thread safe?

查看:110
本文介绍了异步写入套接字线程是否安全?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑 Socket.BeginSend()方法。如果两个线程池线程同时调用此方法,它们各自的消息是否会相互混合或者套接字类是否会阻止这种情况发生?

Consider the Socket.BeginSend() method. If two thread pool threads were to call this method simultaneously, would their respective messages end up mixing with each other or does the socket class keep this from happening?

推荐答案

我发现了一个熟悉的在MSDN论坛上发帖似乎回答了你的问题。

I found a smiliar post on the MSDN forum which seems to answer to your question.



  1. 您可以同时排队多个BeginSends。你不需要锁定


编辑:

更有趣的信息:

如果你在备注MSDN文档部分 BeginSend(),你会发现有趣的回调方法可能与你有关。

If you scroll down a bit in the Remark section of the MSDN doc BeginSend(), you will find interesting use of callback methods that could be relevant for you.


[...]如果您希望在调用BeginSend方法后阻止原始线程,请使用WaitHandle.WaitOne方法。 [...]

[...] If you want the original thread to block after you call the BeginSend method, use the WaitHandle.WaitOne method. [...]

这篇关于异步写入套接字线程是否安全?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆