|
There are to threads:
//thread one:
CSingleLock m_lock(&syn_object);
m_lock.Lock();
/*
.....Doing something
*/
m_lock.UnLock();
/=================================
thread two:
CSingleLock m_lock(&syn_object);
m_lock.Lock();
while (!m_lock.IsLocked());
//continue to do something if thread one finished with thre resource
I want the thread two to wait for the thread one finished 'doing something' before continue but the whole program seems to crash here.
|
|
|
|
|
lisoft wrote:
m_lock.Lock();
while (!m_lock.IsLocked());
Your will always hang on the while line as you just locked m_lock on the previous line.
There is no need to check the lock state as the code will wait on the m_lock.Lock() line until thread one has unlocked the lock.
Remove the while and your code should work better.
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" mYkel - 21 Jun '04
Within you lies the power for good - Use it!
|
|
|
|
|
Your
while (!m_lock.IsLocked());
will never execute because m_lock will always be locked at that step.
Your request cries out for a manual reset event but it looks like you are using something other than an event.
John
|
|
|
|
|
What should I do to let thread two waiting until the thread one finish?
|
|
|
|
|
If I remember right the lock function does not return until it has managed to lock. So checking it is lock after call lock is redundant. The purpose of locking is to allow a thread to manipulate the data with messing up another threads actions. In other words only one thread can read or modify the data at a given time. You do not want to try to copy a string while anouther thread is modifying that same string.
So the answer is YES! Before thread two can work with the data thread one has to stop working with it. Before thead one can work with the data thread two has to stop working with it. The individual threads do not have to stop they just have to stop accessing the shared data long enough for anouther thread to access it.
INTP
"The more help VB provides VB programmers, the more miserable your life as a C++ programmer becomes."
Andrew W. Troelsen
|
|
|
|
|
You do:
Somewhere define an event that both threads know about:
HANDLE hEvent = ::CreateEvent(NULL, TRUE, FALSE, NULL);
which is a manual reset event with unsignalled state to begin with.
Then in your worker thread:
// Do something, stuff, thing or whatever...
// Ok Ready, signal the event
::SetEvent(hEvent);
Then in thread 2 you just wait for the event
// Wait for event to be signalled
::WaitForSingleObject(hEvent, INFINITE);
Execution will continue after the ::WaitForSinglObject as soon as the event
gets signalled.
|
|
|
|
|
Hi,
I am developing a windows COM client application and also a COM server at the same time.
In my workspace there are basically 2 projects, the GUI COM client project and the COM server project.
Before messing around with DEBUG and Release build settings, I was able to setup breakpoints in the COM server code in DEBUG mode and Visual would actually break in that code.
However, I messed around with the DEBUG and Release build settings in order ot test my code in Release mode, and now it doesn't break. I am able to still break in the GUI COM client code just fine but can't break in the COM server code, even when I have the COM server project as the active project.
Anyone know how to fix this?
Thanks in advance!
|
|
|
|
|
It sounds like it is not compiled for debugging or the IDE disabled the break points, when you ran it in release mode. You may need to reset the break points and or rebuild all in debug mode.
INTP
"The more help VB provides VB programmers, the more miserable your life as a C++ programmer becomes."
Andrew W. Troelsen
|
|
|
|
|
Thanks for your reply.
I have checked and recompiled but to no avail. However I just found the solution today and it was a silly mistake on my part. I compiled a release version of my COM Server and regsvr32'd it. When I compiled the DEBUG version the reg script didn't seem to work so all this time I have been trying to step into a RELEASE version of the dll.
Thanks again!
|
|
|
|
|
Hi
I need some help here,
I have some dlls compiled from Visual C++ which I would like to be exposed as Web Services using ASP.
On a system running windows xp.
I have read up on this article :
http://support.microsoft.com/defaul...kb;en-us;239445
1)But this would mean I would have to rewrite majority of code that wasnt written by me (a package handed down to me),
It would be much too time consuming. Is there a way I could using the dlls "as is"?
2)If I have to do it this way, how do I define a method that returns a value?
3)I also tried to create a package in COM+ using the Component Services. However I had trouble linking up all the required files.
(is this a correct method anyway?)
http://support.microsoft.com/kb/223406/en-us
I cannot find any articles that detail the process, even a link to something I should read up on would be greatly appreciated.
Thank you.
Eugene
|
|
|
|
|
I need to work with an 8 byte integer... but when i do a sizeof long int it gives me a size of 4 bytes.. how do i get it to work with 8 bytes?
Kuniva
--------------------------------------------
|
|
|
|
|
Use the MS-specific __int64 type.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
Want a Boost forum in Code Project? Vote here[^]!
|
|
|
|
|
Can someone help me with my program. I am doing a shortest path program in C++ MS Visual Studio.net using MFC and I need to display the different points(circles with the number on them). I have placed a group box on my dialog box and i want to place the points on the group box. So far I have three edit control boxes. One for point number, and the other two are for x and y coordinates. I have also placed a button to add the point once the data is set in the edit control boxes. Can someone help me display the points please. Also if there is an easier way to display the points can you let me know. I have tried to understand the article on Dijkstra's Algorithm that is posted here at this website but I cant understand to much
|
|
|
|
|
i can used LCD but i can not use "printf" how use it??
|
|
|
|
|
|
You will probably have to write your own.
If you have a library that can write strings to the display, then you can use sprintf(...) to format a string then send that to the display.
Good Luck!
INTP
"The more help VB provides VB programmers, the more miserable your life as a C++ programmer becomes."
Andrew W. Troelsen
|
|
|
|
|
Hello all. I'm using Windows' GetFileSize function to get the file size:
<br />
HANDLE hFile = 0;<br />
DWORD dwLowSize = 0;<br />
DWORD dwHighSize = 0;<br />
QWORD qwTotSize = 0;
<br />
hFile = CreateFile(m_pFileInfo->szFileName, GENERIC_READ, FILE_SHARE_READ,<br />
NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);<br />
dwLowSize = GetFileSize(hFile, &dwHighSize);<br />
CloseHandle(hFile);<br />
Now, I goy dwLowSize and dwHighSize. How can I get the __int64 value of the both? How should I combine dwLowSize and dwHighSize in order to get the complete size of the file?
Thanks.
KK.
Hear my words, that I might teach you,
Take my arms, that I might reach you,
but my words like silent raindrops fell,
echoed the will of silence...
|
|
|
|
|
ULARGE_INTEGER li;
li.LowPart=dwLowSize;
li.HighPart=dwHighSize;
__int64 i=li.QuadPart;
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
Want a Boost forum in Code Project? Vote here[^]!
|
|
|
|
|
im thinking you could do this, (looked at MAKELONG, MAKEWORD macros)
#define MAKEQWORD(a, b) ((QWORD)(((DWORD)(a)) | ((QWORD)((DWORD)(b))) << 32))
qwTotSize = MAKEQWORD( dwLowSize, dwHighSize );
|
|
|
|
|
Hi
I need some help for the follwoing state.
when i use for(....)
statement the CPU prformance becomes 100%
when i use Sleep(..) function the program performance becomes more slower.
i need some techinques for using loop with large rang with minmal CPU performance .
plesea some help.
thanx alot
BY.
On Earth nothing impossible,
while your mind running.
Faroqtam
|
|
|
|
|
If you are processing a lot of data, Sleep is about your only choice. You must chose between fast data processing and program performace. It is all a balancing act; a single CPU can only do so much and every but wants a slice of its time. The best you can do is to run profiling to see where the bottle necks are (slow code) and optimize those functions that are taking to long to do there job.
Good Luck!
INTP
"The more help VB provides VB programmers, the more miserable your life as a C++ programmer becomes."
Andrew W. Troelsen
|
|
|
|
|
What exacly you want to do ?
why would you want to use Sleep ? it will stop the loop from looping ( and suspend the application ).
If the software loops, and is taking 100% of the CPU, it is because the OS decided that nothing else important needs the CPU;
I'm not sure what you mean by "minmal CPU performance" ? even a low priority process will be put to work when nothing else happens.
Maximilien Lincourt
Your Head A Splode - Strong Bad
|
|
|
|
|
See the section "Responding to user input while performing a long task" in this[^] article.
/ravi
My new year's resolution: 2048 x 1536
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
Hi .
Thanx alot.
On Earth nothing impossible,
while your mind running.
Faroqtam
|
|
|
|
|
well if the processing that u want to is not that important ,give ur code in the OnIdle() function.....
maybe that could help.....
|
|
|
|