473,396 Members | 1,918 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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 1551
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_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.
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
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...
14
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...
3
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...
3
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
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...
3
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...
11
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...
1
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....
45
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
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.