473,769 Members | 2,106 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Why does .NET raise_XXX proxy code lock on a mutex.

Maybe I'm not understanding things.

I have a multi-threaded callback producer (Unmanaged C++), which fires
into a managed proxy class, which in turn calls into a managed C++
consumer (mixed mode DLL). From the managed C++ class I have defined
__events, which are consumed by a C# class. This works perfectly well;
All the callbacks end up in the managed c++ class and successfully
call into the C# code, however the raise_XXX method for the event
appears to lock on a mutex, so if the C# consumer takes too long,
events are queued/blocked in the managed C++ code. This seems like
quite a poor implementation. I know how to work around it, however I'd
prefer to use the delegate-event model, but obviously can't live with
it blocking!

So I have 2 questions.

1. Why was it implemented this way.
2. Is there any way to have it not do this (some sort of compiler
directive??)

Thanks.

D.

Feb 16 '07 #1
3 1148
I have a multi-threaded callback producer (Unmanaged C++), which fires
into a managed proxy class, which in turn calls into a managed C++
consumer (mixed mode DLL). From the managed C++ class I have defined
__events, which are consumed by a C# class. This works perfectly well;
All the callbacks end up in the managed c++ class and successfully
call into the C# code, however the raise_XXX method for the event
appears to lock on a mutex, so if the C# consumer takes too long,
events are queued/blocked in the managed C++ code. This seems like
quite a poor implementation. I know how to work around it, however I'd
prefer to use the delegate-event model, but obviously can't live with
it blocking!

So I have 2 questions.

1. Why was it implemented this way.
2. Is there any way to have it not do this (some sort of compiler
directive??)
raise_XXX checks handler on null and then if it's possible calls handler
itself. To avoid concurency problems it puts these two operations in a lock.
You can call the handler as:

XXXHandler handler = this->xxxHandler;

if (handler != 0)
handler->Invoke(...);

Result is the same.
--
Vladimir Nesterovsky
Feb 17 '07 #2
raise_XXXchecks handler on null and then if it's possible calls handler
itself. To avoid concurency problems it puts these two operations in alock.
"To avoid concurrency problems" is a pretty poor reason for a mutex
lock....I would have thought that currency issues in a multi-threaded
application would be the responsibility of the programmer! Unless,
there is a way to switch the locking semantics, I'd file this one
under one of the poorest default framework implementations from
Microsoft, EVER!
You can call the handler as:

XXXHandler handler = this->xxxHandler;

if (handler != 0)
handler->Invoke(...);

Result is the same.
....so you're saying that there is no way to override the global
locking for delegates?

D.

Feb 19 '07 #3
>raise_XXXcheck s handler on null and then if it's possible calls handler
>itself. To avoid concurency problems it puts these two operations in
alock.

"To avoid concurrency problems" is a pretty poor reason for a mutex
lock....I would have thought that currency issues in a multi-threaded
application would be the responsibility of the programmer! Unless,
there is a way to switch the locking semantics, I'd file this one
under one of the poorest default framework implementations from
Microsoft, EVER!
>You can call the handler as:

XXXHandler handler = this->xxxHandler;

if (handler != 0)
handler->Invoke(...);

Result is the same.
MC++ generates such a lock in order to prevent null reference exception in
raise_XXX method:

if (this->handler != 0)
this->handler->Invoke(...);

I did not see that C# generated raise_XXX method at all. Thus MC++ provides
more but in safe box.
...so you're saying that there is no way to override the global
locking for delegates?
Do not know exactly. It's not so hard however to call handler->Invoke(...)
directly.

--
Vladimir Nesterovsky
Feb 19 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
6182
by: Marco Bubke | last post by:
Hi There is the Lock object in the threading module. But there is no medode there I could aquire a scoped lock like: mutex = threading.Lock() my_lock = mutex.scoped_acquire() # maybe scoped_lock() #now this stuff is locked
14
2805
by: Antoon Pardon | last post by:
The queue and condition class allow threads to wait only a limited time. However this currently is implemented by a polling loop. Now for those who like to avoid polling I have here a Tlock class that allows for a timeout but doesn't use polling. All comments are welcome. ----------------------- Tlock.py -------------------------------
3
8640
by: Ron Vecchi | last post by:
I have a single line file where the line will be read and updated each time it is opened. My question is I need to open it with a lock so noone else can read or write to it untill the lock is released. The problem seems that what If it is locked and A different request tries to open it. From what I understand an exception will be thrown. It is critical that each request reads the file. Is there an easy way to make a request wait...
3
2958
by: g | last post by:
hello! here is some code: #ifndef RESOURCE_H_ #define RESOURCE_H_ #include <boost/date_time/gregorian/gregorian.hpp> #include <boost/thread/mutex.hpp>
3
1564
by: daniel | last post by:
Maybe I'm not understanding things. I have a multi-threaded callback producer (Unmanaged C++), which fires into a managed proxy class, which in turn calls into a managed C++ consumer (mixed mode DLL). From the managed C++ class I have defined __events, which are consumed by a C# class. This works perfectly well; All the callbacks end up in the managed c++ class and successfully call into the C# code, however the raise_XXX method for the...
7
3045
by: tiffini | last post by:
Hi, We have a lot of OS's to support. So we created a mutex class with sieze and release like so class foo{ private: volatile int m_lock; public:
3
5591
by: NaeiKinDus | last post by:
Hello, i'm trying to program a thread that would be locked (by a mutex) and that would only be unlocked once that a function (generating data) is done. The purpose is to generate data, and unlock the mutex in order to activate the thread once the data is generated. I have to do it this way, i can only call the thread if the data are generated. ******************************************************** step 1: initialize the mutex
11
3693
by: Lamont Sanford | last post by:
Given an object of type Mutex, what method or property should be called to determine if it is currently owned? I could call WaitOne(0,false) -- and if the return value is false, I could deduce that the Mutex is already owned... but this has the unwanted side effect of seizing ownership of the Mutex in the case where the Mutex is NOT already owned. I'm looking for something like an "IsOwned" property.
1
3247
by: chsalvia | last post by:
I was browsing through the souce code for the boost mutex implementation just to understand how the library works. I get the basic idea: a mutex object is associated with a scoped_lock object. The scoped_lock object calls private member functions of the mutex, specifically mutex::do_lock and mutex::do_unlock via static functions defined in the lock_ops class. My question is, where is the actual platform-specific call to actually lock...
45
4431
by: Chris Forone | last post by:
hello group, is there a chance for other functions to get the lock if i have following loop: while (running) { Lock local(mutex); }
0
9589
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10216
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9997
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7413
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6675
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5310
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3965
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3565
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.