473,761 Members | 8,813 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

BUG: Unified Event Model (Native) inject empty Lock/Unlock()

M.C
Following is a snap-shot of compiler created code when using UEM, use /Fx:

struct __EventCritical SectionStub
{
void Lock() {}
void Unlock() {}
};

....

__EventCritical SectionStub __EventingCS;

__EventingCS.Lo ck() and __EventingCS.Un lock() is called in several important
section such as __AddEventHandl er__XXXX and firing event. But due to the flaw
in __EventCritical SectionStub, corruption happen when using UEM in
multithread project.
From MSDN: Visual C++ Concepts: Adding Functionality - > Introduction to the
Unified Event Model

"..The model supports single- and multithreaded usage and protects data from
simultaneous multithread access..."
Am I missing something, or Visual C ...oops, I did it again?
Nov 17 '05 #1
1 1382
M.C
#define THREAD_COUNT 64
// Comment the following to see the problem
#define EXPLICIT_LOCK
[event_source(na tive, optimize=speed)]
class CSource
{
public:
__event void Print(LPCTSTR psz);

};
[event_receiver( native)]
class CReceiver
{
private:
#ifdef EXPLICIT_LOCK
CComAutoCritica lSection g_Lock;
#endif

public:
void Hook(CSource* p)
{
__hook(&CSource ::Print, p, &CReceiver::Pri nt);
}

void Print(LPCTSTR psz)
{
static TCHAR sz[64] = {0};
#ifdef EXPLICIT_LOCK
g_Lock.Lock();
#endif
::lstrcpy(sz, psz);
for(int i=0; i < ::lstrlen(psz); i++)
_puttch(sz[i]);
::ZeroMemory(sz , sizeof(sz));
#ifdef EXPLICIT_LOCK
g_Lock.Unlock() ;
#endif
}
};
DWORD WINAPI ThreadProc(LPVO ID pParam)
{
CSource* ps = static_cast<CSo urce*>(pParam);
TCHAR sz[64] = {0};

::wsprintf(sz, _T("Hello World! (%d)\n"), ::GetCurrentThr eadId());
::Sleep(rand() % 1000);
__raise ps->Print(sz);
return 0;
}
int _tmain(int argc, _TCHAR* argv[])
{
HANDLE h[THREAD_COUNT] = {NULL};
CSource s;
CReceiver r;
r.Hook(&s);

srand((unsigned )time(NULL));
for(int i=0; i < THREAD_COUNT; i++)
h[i] = DefaultThreadTr aits::CreateThr ead(NULL, 0, ThreadProc, &s, 0, NULL);
::WaitForMultip leObjects(THREA D_COUNT, h, TRUE, INFINITE);
for(i=0; i < THREAD_COUNT; i++)
::CloseHandle(h[i]);
return 0;
}
Nov 17 '05 #2

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

Similar topics

0
1101
by: Kevin Jiang | last post by:
the injected line is this: struct __EventingCriticalSectionStub { void Lock() { } void Unlock() { }
3
2081
by: Ashok Kumar K | last post by:
Hi all, Where can I get some insight on using the __hook, __unhook, event_source and event_receiver for specifically COM events. The documentation given in MSDN is very minimal. I have the following scenario Server (COM event source) is written in VC++ 6.0 using ATL (event interfaces can be either dispinterface / IDispatch based) Client (COM event receiver) is written in VC++ 2003 using attributed programming and unified event handling
8
4100
by: Jun | last post by:
hi, just want to know if std::queue empty() is thread safe (running on 2 or more thread)... so i can do, if( !queue.empty() ) { lock() .... unlock()
16
1740
by: Edward Diener | last post by:
After spending more than a day reducing a complicated compiler bug to a simple case I reported it to the MSDN Product Feedback Center as a bug just now. However this bug is completely stymying my development of a VC++ component. Does Microsoft still offer any free bug reporting cases for VS2005, as they did two for VS2003 so that I can talk with a technical representative directly to try to find a workaround for the compiler bug ? While...
1
1916
by: Bill | last post by:
Hi all, I've got my self a bug that I am out of ideas on how to fix... A section of my program launches a thread to handle a FIFO work buffer, I make the fifo as a single link list, the head node is set to NULL when the buffer is empty by the handler thread. One or more ( typicaly 3 or 4 ) request threads are used to place objects on to the work que.
3
4248
by: freesteel | last post by:
/* Is this a bug in Py_NewInterpreter? The function below "MyThread" is instantiated from a windows worker thread, but I don't think that is relevant. (I can try this on a linux box, but I would have to compile a python library with debugging enabled.)
0
4583
by: Kurt B. Kaiser | last post by:
Patch / Bug Summary ___________________ Patches : 349 open ( +7) / 3737 closed (+25) / 4086 total (+32) Bugs : 939 open (-12) / 6648 closed (+60) / 7587 total (+48) RFE : 249 open ( -8) / 278 closed (+12) / 527 total ( +4) New / Reopened Patches ______________________
3
2377
by: Lars Uffmann | last post by:
I have this wxWidgets OnButtonClick event handler, that apparently holds a lock on all widgets in my form, but this event handler is supposed to end a thread in the background - while that thread is supposed to update widget content. So if I want to wait for the thread to end in the event handler, I have 2 threads waiting on each other - with the one in the background waiting to access the widget content. My current workaround is to...
45
4428
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
9554
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
9376
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10136
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...
0
9811
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8813
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7358
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
6640
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
5266
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
3911
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

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.