|
Hi Yuriy,
Yes you understand correctly. The thread handle will be valid if m_bAutoDelete is set to FALSE. You will need to perform cleanup yourself of the m_SomeThread object.
Best Wishes,
-David Delaune
|
|
|
|
|
Randor wrote: As I have previously mentioned both of our excellent recommendations will avoid the deadlock.
David, no offence taken!
I find it interesting and there's a possibility that someone might learn something and it could be me.
However, I think you have misread my previous post (or possibly posts).
I figure this as I am still under the impression that the OP waits on the thread handle before spawning a new thread, as I've stated previously.
- or -
Do you really mean that you have experienced a scenario where you have a handle that:- you provide as argument to e.g.
::WaitForSingleObject() - is valid so the waiting function doesn't return
WAIT_FAILED immediately - has not assumed a signalled state (which would make the waiting function return immediately)
- becomes signalled, closed and recycled behind scenes
in a way that makes the waiting function hang?
(This is how I interpret your statement.)
I must say I seriously doubt that as it would mean a catastrophic design flaw of the synchronization mechanism of the operating system in my opinion.
Randor wrote: If you like I can create a sample application which continuously spawns/terminates a self deleting thread and then force a context switch before calling WaitForSingleObject. The alertable wait state will return 99% of the time and eventually deadlock.
If you are able to do that and wait on the thread handle before creating a new thread, I'd be delighted to see it.
I will even try and create such an abomination myself.
But if this is the case I don't see how any of our proposed solutions may prevent this deadlock.
Randor wrote: The cause of the deadlock will be a valid handle which is invalid in the context of the process calling WaitForSingleObject. I guess it would be better to use a different terminology as invalid seems to be confusing you.
Well, I wasn't confused until I read the underlined part above. But the confusion is more about what you mean rather than whether a handle is valid or invalid.
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
Hi Roger,
Roger Stoltz wrote: Do you really mean that you have experienced a scenario where you have a handle that:
Let me clarify the scenario I am presenting:
1.) Engineer creates a CWinThread object with m_bAutoDelete set to TRUE.
2.) CWinThread is started.
3.) A context switch takes place in GUI thread.
4.) CWinThread completes and exits and the handle is dereferenced.
5.) GUI thread resumes from context switch.
6.) GUI calls WaitForSingleObject on the CWinThread->m_hThread with INFINITE.
7.) The handle is a valid handle, another object has been assigned this identifier.
8.) WaitForSingleObject never returns.
Yes, I have encountered this before in the real world. You can produce an application which exibits this handle recyling deadlock behavior.
Roger Stoltz wrote: I must say I seriously doubt that as it would mean a catastrophic design flaw of the synchronization mechanism of the operating system in my opinion.
I'm surprised that you have not read about this before. Its the same thing with window handles. I have noticed that you often reference Dr. Joseph Newcomer in your posts. What is occuring under the hood is essentially the same principles of the flaw described in Avoiding Multiple Instances of an Application[^] and window handles. Window handles can be closed and/or re-assigned to other windows. This can lead to deadlocks/race conditions. It is the essentially the same for thread/process handles. Handles cannot always be relied upon and they may be valid, invalid or re-assigned.
You can probably find other software engineers describing this flaw:
DuplicateHandle CWinThread Newcomer[^]
Best Wishes,
-David Delaune
|
|
|
|
|
|
Hi Roger,
Now I am uncertain if this was the problem Yuriy was having. I just read the entire thread again and noticed that in this post[^] Yuri states that "99% of cases the thread is already terminated, when the WaitForSingleObject() is called."
I am starting to think there may have been a serious design flaw. I guess we should have asked to see some code.
Anyway I am leaving the office soon.
Have a good night,
-David Delaune
|
|
|
|
|
Well, the OP's problem could still be the one we've been discussing.
There is a possibility that the handled gets recycled between thread termination and the call to ::WaitForSingleObject() . When he claims that the thread is already terminated in 99% of the cases I doubt he really checks the return value; the wait may have failed since the handle has been closed but he doesn't care because it means that the thread doesn't run any longer.
As I wrote earlier I still think he has introduced a race condition where the worker thread somehow sends a message to the main thread instead of posting. If the main thread has already assumed its waiting state on the thread handle the deadlock is a reality.
This is in my opinion the most common reason for deadlocks when it comes to multithreading and would most definitely result in the behaviour he has described.
It may be that he's calling a framework function that disguises the ::SendMessage() call.
The probability for a design flaw I guess is very close to 100%.
I will have a good night; it's almost 1:00AM in Sweden and I'm about to hit the sack.
I wish you a good night as well!
--
Rog
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
You could create the thread in a suspended state, retrieve the thread handle then (before it's started executing) and store it way with the thread object pointer?
But you probably shouldn't do that anyway. I'd use MsgWaitForMultipleObjects[^] so I could both wait for the thread and dispatch window messages (you'll need to write your own message loop).
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
When the user clicks in the dialog too soon and you do WaitForSingleObject you are blocking the GUI thread of the dialog. i.e. it hangs. Never block your GUI thread. Instead use a message box to inform user that he has clicked too soon and then simply return from the OnClick handler. Also, use an hour glass cursor while the background thread is running to inform user that clicking isn't going to work. You could disable some or all of the controls on the dialog just before kicking off the background thread to prevent the user from doing anything while the thread runs. Then enable them once the thread is complete and it is safe to click again. Also consider that you can't allow the dialog to close while the background thread is running.
|
|
|
|
|
Hi,
I created an ActiveX(MFC) control in VS08 with the MFC wizard.
In the myOCXCtrl.cpp file I'm trying to exit the ActiveX, e.g. in the mouse move event.
What ever I do, I just can't unload/exit/delete the ActiveX (I'm using TstCon32.exe for testing it)
Right clicking on the ActiveX in the test container choosing "Delete" just does what i want:
myOCXCtrl::OnDestroy() is called, the dtor is called and the activeX terminates.
But how can I do this from within the activeX?
A 'this->DestroyWindow();' ends up in an assertion somewhere in 'ctlnownd.cpp'.
With 'this->PostMessage(WM_DESTROY);' nothing happens.
'exit(0)' terminates the test container, too. (what is not what i want)
Any idea, anybody?
Best regards!
|
|
|
|
|
All you need to do is release all references to the control. That can be a little more involved than just nulling your pointer to the control - you'll need to do things like unadvise event sinks etc as well.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
There is already a mechanism for this specified by COM: release all references/interfaces to the COM server.
[warning]
You're trying to break some COM rules. You may end up with one or more clients that are still trying to use interfaces that your server exposes a client has called the method you're trying to implement. That will of course result in a serious crash since the server simply isn't there any longer.
[/warning]
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
As the other members have stated the problem is that you have not called the Release method to decrement the reference count. Here is some documentation:
Reference Counting[^]
Best Wishes,
-David Delaune
|
|
|
|
|
Hi there.
I'm trying to write an aplication that will automaticaly initiate a user login, if the user is logged off for a given period of time. (right now it's in c#, but it may as well be in C++)
I've tried using the ADVAPI32.DLL's function LogonUser, but apparently that is used for impresonation (am i wrong?).
So, how is that done?
In addition, i failed to find a way to check if a specific user is logged on or not.
Any idea?
If there is an easier way to do the auto-login, i will of course be glad to hear it.
Thanks,
SummerBulb
|
|
|
|
|
|
Been there.
That configuration is only good for the first logon (when you turn on the computer). If a logged-on user logs off, it won't log him back on.
|
|
|
|
|
I take my words back and aplogise.
It works perfectly.
Thanks!
|
|
|
|
|
Hi to All,
I had this question came up. What is the differrence between C++ and VC++.
What I think is that, VC++ is an IDE . It is the same as C++, with an visual environment with ease of creating applications.
I want to clarify, if I am correct?Or if any othere points we need to mention for the same question.
Thanks in advance
-----------------------------
I am a beginner
|
|
|
|
|
I suppose no one ever asked such question [^].
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
hrishiS wrote: What is the differrence between C++ and VC++.
C++ in general refers to the language, independent of compiler.There are various compilers for C++ like C++ in windows(VC++),linux(GCC) etc.
VC++ is Microsoft's Compiler of C++,with it's own libraries primarily developed for MS Operating Systems.
This http://en.wikipedia.org/wiki/List_of_compilers#C.2FC.2B.2B_compilers[^] should help you.
Hope that gives a start
"Every morning I go through Forbes list of 40 richest people in the world. If my name is not in there, I go to work..!!!"
|
|
|
|
|
QuickDeveloper wrote: VC++ is Microsoft's Compiler of C++,with it's own libraries primarily developed for MS Operating Systems.
Uhm...
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
thanks a lot for the reply
-----------------------------
I am a beginner
|
|
|
|
|
I want to show the .PDF file on every help button click.
So I have to load the .PDF file when every user clicks the help button but at the same time I have to show the related topic on which help is required.
So how should i implement this?
Please tell that how I am going to search the concern text of topic in the .PDF file or the help file.
|
|
|
|
|
I assume tbis is from within your own software?
Your problem has two parts...
1/ Capturing help requests in your program.
Have a look inside CWinApp::OnHelp, and related overridables. Put breakpoints in. See what happens when you press f1 *now*.
2/ When you work out which function to override, then use that to fire up a pdf instead. As for going to a specific place inside the PDF, have a look at: http://partners.adobe.com/public/developer/en/acrobat/PDFOpenParameters.pdf[^]
In there, it shows how to open a pdf, and go to a nameddest inside the PDF. I assume these are bookmarks, or like anchors in HTML.
I'm sure there are other help pages on the adobe website that will be even more useful. Enjoy the search!
Iain.
I have now moved to Sweden for love (awwww).
If you're in Scandinavia and want an MVP on the payroll (or happy with a remote worker), or need cotract work done, give me a job! http://cv.imcsoft.co.uk/[ ^]
|
|
|
|
|
I can see why you were voted down - you posted the indentical question 20 minutes before.
Were you upset people didn't rush to answer you?
Iain.
I have now moved to Sweden for love (awwww).
If you're in Scandinavia and want an MVP on the payroll (or happy with a remote worker), or need cotract work done, give me a job! http://cv.imcsoft.co.uk/[ ^]
|
|
|
|
|
Hi,
I am quite confused: I want to open long filenames using _taccess, so I wrap my filenames with quotes, i.e. instead of c:\test.txt, I pass "c:\test.txt" or "c:\my folder with spaces\filename with spaces.txt" to _taccess, but it tells me that the file was not found. Which is the correct way to handle long filenames? I always thought that putting them in quotation marks will work just fine, but it doesn't.
Thanks for any help
|
|
|
|