WCF:回叫重入不清楚.为什么会发生这种死锁 [英] WCF : Callback reentrancy is not clear. Why this dead lock take place

查看:47
本文介绍了WCF:回叫重入不清楚.为什么会发生这种死锁的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在阅读Juval Lowy的一篇文章.下面的部分对我来说不清楚.我的问题是:为什么回调re需要锁的所有权?我的意思是调用回调的线程正在等待回调返回.因此,此线程应在回调返回之后恢复,就像其他任何方法调用一样.

服务可能还希望在执行合同操作期间调用传入的回调引用或调用回调列表.但是,不允许这样的调用,因为默认情况下,服务类配置为单线程访问:该服务实例与一个锁关联,并且一次只有一个线程可以拥有该锁并访问该服务实例.在操作期间调出客户端要求在调用回调时阻塞服务线程.问题在于,一旦回调返回,处理来自客户端的回复消息就需要拥有同一锁,因此会发生死锁.
为了避免出现死锁,如果单线程服务实例尝试回调其客户端,则Windows Communication Foundation将抛出InvalidOperationException

I was reading an article by Juval Lowy. Below section is not clear to me.My Question is : Why callback re requires the ownership of lock? I mean the thread in which the call back is called is waiting for callback to return.so this thread should resume after the callback returns, just like any other method call.

The service may also want to invoke the callback reference passed in or invoke the list of callbacks during the execution of a contract operation. However, such invocations are disallowed because by default the service class is configured for single-threaded access: the service instance is associated with a lock, and only one thread at a time can own the lock and access the service instance. Calling out to the clients during an operation requires blocking the service thread while invoking the callbacks. The problem is that processing the reply message from the client once the callback returns requires ownership of the same lock, and so a deadlock would occur.
To avoid a deadlock, if the single-threaded service instance tries to call back to its clients, Windows Communication Foundation will throw an InvalidOperationException

推荐答案

不需要所有权,但是如果回调具有访问某些共享库的权限,则可能是必需的.就这样.
有关具体细节,请联系Juval Lowy.我没有阅读这篇文章,因为您没有给我参考.

最好的问候,
-SA
In general case, a callback does not require ownership of a lock, but it can be required if the callback has access to some shared objects. That''s it.
For the concrete detail, please address to Juval Lowy. I did not read the article, because you did not give me a reference.

Best regards,
—SA


我假设您是指本文 ^ ].该文章中真正的好东西位于排队的发布者和订阅者"标题下,该标题描述了如何将WCF与MSMQ一起使用,从而实现真正的异步操作.

看看 WCF/WPF聊天应用程序 [
I assume you are referring to this article What You Need To Know About One-Way Calls, Callbacks, And Events[^]. The real goodie in that article is under the heading "Queued Publishers and Subscribers" which describes how to use WCF with MSMQ, enabling true asychronous operation.

Have a look at WCF / WPF Chat Application[^], it''s a better example.

Best regards
Espen Harlinn


这篇关于WCF:回叫重入不清楚.为什么会发生这种死锁的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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