473,507 Members | 3,112 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help with CEvent/CMultiLock

Okay, I'm trying to synchronize two threads using CEvent and
CMultilock. What I need to achieve here is that they can execute in
parallel until they reach a succession of "barriers" (borrowing a VMS
term). I am attempting this by declaring two events in each of the
threads. Each event has the same name in each thread.

The problem is that the CMultiLock Lock() function returns
successfully SOMETIMES but not always. Another thing I don't
understand is why the TRACE call to IsLocked always shows a state of
0, just after I set the event!

Any help is appreciated. The code follows:

BOOL CColCtl::OnInitDialog()
{

CDialog::OnInitDialog();

// create a multilock to synchronize startup of the two threads.
CEvent sme(0, 1, START_MAIN_EVENT), sce(0, 1, START_COLL_EVENT);
CSyncObject* events[2];
events[0] = &sme;
events[1] = ⪰
CMultiLock ml(events, 2);

// start the data collection thread
mCS.bFakeData = TRUE;
CWinThread* mCollThd = AfxBeginThread(CollectData, &mCS);
TRACE0("Collect thread started\n");

// ... other processing here ...

// wait for both threads to get to the first barrier
TRACE1("sme succ %d\n", sme.SetEvent());
TRACE1("sme state %d\n", ml.IsLocked(0));
if (ml.Lock() != -1) {
sme.ResetEvent();
TRACE0("Main thread hit barrier 1\n");
Sleep(3000); // simulated processing
TRACE0("Main thread leaving barrier 1 section\n");
} // end if Lock
else {TRACE0("Main lock failed\n");}

TRACE0("Main exit\n");
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
static UINT CollectData(void* pParam) {

CCollShare* pCS = (CCollShare*)pParam;
TRACE0("CollectData started\n");

// create a multilock to synchronize startup of the two threads.
CEvent sme(0, 1, START_MAIN_EVENT), sce(0, 1, START_COLL_EVENT);
CSyncObject* events[2];
events[0] = &sme;
events[1] = ⪰
events[2] = &sde;
CMultiLock ml(events, 2);

// other processing here

// wait for both threads to get to the first barrier
sce.SetEvent();
TRACE1("sce succ %d\n", sce.SetEvent());
TRACE1("sce state %d\n", ml.IsLocked(1));
if (ml.Lock() != -1) {
sce.ResetEvent();
TRACE0("CollectData hit barrier 1\n");
Sleep(5000); // simulated processing
TRACE0("CollectData leaving barrier 1 section\n");
} // end if Lock
else {TRACE0("CollectData lock failed\n");}

TRACE1("CollectData ended %d\n", pCS->bFakeData);

return 0;

} // end CollectData
Nov 16 '05 #1
0 1623

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

Similar topics

21
6487
by: Dave | last post by:
After following Microsofts admonition to reformat my system before doing a final compilation of my app I got many warnings/errors upon compiling an rtf file created in word. I used the Help...
9
4377
by: Tom | last post by:
A question for gui application programmers. . . I 've got some GUI programs, written in Python/wxPython, and I've got a help button and a help menu item. Also, I've got a compiled file made with...
4
3323
by: Sarir Khamsi | last post by:
Is there a way to get help the way you get it from the Python interpreter (eg, 'help(dir)' gives help on the 'dir' command) in the module cmd.Cmd? I know how to add commands and help text to...
2
6374
by: Sudheer Kareem | last post by:
Dear All Please tell me how to assosiate help files with my Vb.net Project. Regards Sudheer
6
4304
by: wukexin | last post by:
Help me, good men. I find mang books that introduce bit "mang header files",they talk too bit,in fact it is my too fool, I don't learn it, I have do a test program, but I have no correct doing...
6
2984
by: d.warnermurray | last post by:
I am doing a project for school that involves creating help files for a html authoring tool. If you could help me with answers to some questions it would really help. 1. What tasks do you expect...
5
2963
by: Craig Keightley | last post by:
Please help, i have attached my page which worksin IE but i cannnot get the drop down menu to fucntion in firefox. Any one have any ideas why? Many Thanks Craig ...
0
1136
by: Thomas | last post by:
Hello everybody, I have a C++ application which gives a DLL 2 handles from cevent objects. Now I need to use this DLL with C#, but I don't know how to create a counterpart of the cevent object...
4
2386
by: scorpion06 | last post by:
I would like to know how can i change "CMAP" and "CEvent" (class MFC) to an algorithm on C++. thank you.
0
7308
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,...
1
7023
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
7479
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...
0
5617
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,...
1
5037
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...
0
4702
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...
0
3188
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...
0
3178
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
410
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...

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.