473,385 Members | 1,782 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,385 software developers and data experts.

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 __EventCriticalSectionStub
{
void Lock() {}
void Unlock() {}
};

....

__EventCriticalSectionStub __EventingCS;

__EventingCS.Lock() and __EventingCS.Unlock() is called in several important
section such as __AddEventHandler__XXXX and firing event. But due to the flaw
in __EventCriticalSectionStub, 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 1367
M.C
#define THREAD_COUNT 64
// Comment the following to see the problem
#define EXPLICIT_LOCK
[event_source(native, optimize=speed)]
class CSource
{
public:
__event void Print(LPCTSTR psz);

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

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

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(LPVOID pParam)
{
CSource* ps = static_cast<CSource*>(pParam);
TCHAR sz[64] = {0};

::wsprintf(sz, _T("Hello World! (%d)\n"), ::GetCurrentThreadId());
::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] = DefaultThreadTraits::CreateThread(NULL, 0, ThreadProc, &s, 0, NULL);
::WaitForMultipleObjects(THREAD_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
by: Kevin Jiang | last post by:
the injected line is this: struct __EventingCriticalSectionStub { void Lock() { } void Unlock() { }
3
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...
8
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
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...
1
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...
3
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...
0
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...
3
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...
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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,...

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.