|
Hi, All
I am Creating a Thread Using CreateThread() Function and in it's procedure I am performing my Task
But on a Specific Condition i want Terminate it and for it I am using TerminateThread() Function but it Return 0 Which indicate Failure as per msdn it require that my CreateThread() handle must have THREAD_TERMINATE access How Can i Set it?
Thanks
Mitesh
~Khatri Mitesh
khatrimitesh@hotmail.com
Bikaner (Rajasthan)
INDIA
|
|
|
|
|
~Khatri Mitesh~ wrote: But on a Specific Condition i want Terminate it and for it I am using TerminateThread() Function
You should never end a thread this way. A much better approach is to simply set a flag that is checked regularly by your thread. When the flag is set, the thread knows it has to end and it will do it naturally (instead of being killed in the middle of something).
|
|
|
|
|
You should never use TerminateThread(), since it can easly cause deadlock in your application. Check this[^] and the documentation from MSDN below.
MSDN: TerminateThread is a dangerous function that should only be used in the most extreme cases. You should call TerminateThread only if you know exactly what the target thread is doing, and you control all of the code that the target thread could possibly be running at the time of the termination. For example, TerminateThread can result in the following problems:
Well, you could use event object to implement same behavior. Well, in the mean while i found this thread[^] also. May be useful to you.
Regards,
Jijo.
_____________________________________________________
http://weseetips.com[ ^] Visual C++ tips and tricks. Updated daily.
|
|
|
|
|
As previous replies stated, you should never call TerminateThread (since there are better ways to handle your scenario). Anyway, if you're stuck on your (bad) idea, what about reading the documentation [^]?
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]
|
|
|
|
|
we have four threads which have to call with milliseconds interval (66.67ms,200ms,10ms,100ms these are time intervals for resuming threads)
"windows timers" does not provide accuracy (perfect) by using windows timers results are not well accurate but if we use multimedia timers then there is problem of synchronization. processor does not takes windows event (mean mouse click or key pressed or repaint window etc etc these event take log time of interval to process )
we need much accuracy and fast user intraction with my application (mean click and key press etc etc)
what can be solution? and how can sychronize windows events with multimedia timers??
|
|
|
|
|
Are you trying to pass multimedia timer events into your window handling code or the other way round?
If it's the first option and you're using timerSetEvent , you could do this:
- For each timer events, create a kernel event.
- Create the the timer event using the flag
TIME_CALLBACK_EVENT_SET and pass the kernel event handle as the callback procedure. - Create a thread with a function that (in a loop) does a
WaitForMultipleObjects , waiting for any one of the kernel events set by the timers. - When an event is detected in the thread function, POST a window message as appropriate.
The general pattern of setting kernel events with timer events allows you to transfer the timer event into another thread.
BTW - do you realise that the multimedia timer API is obsolete and could easily disappear soon? You might be better off using timer queues (see this article for a description[^]) that, as far as I can tell, have the same resolution and accuracy as multimedia timers. Also, it looks like they're better tied into the Windows synchronisation functionality.
|
|
|
|
|
Stuart Dootson wrote: do you realise that the multimedia timer API is obsolete and could easily disappear soon?
Hi Stuart,
Where did you hear that? Link?
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Mark Salsbery wrote: Hi Stuart,
Where did you hear that?
I told him.
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]
|
|
|
|
|
So where did YOU hear that?
I don't see any indication that the multimedia timer APIs are deprecated.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Mark Salsbery wrote: So where did YOU hear that
If I remember well, Stuart Dootson told me.
Mark Salsbery wrote: I don't see any indication that the multimedia timer APIs are deprecated.
Because we should keep it secret.
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]
|
|
|
|
|
CPallini wrote: Because we should keep it secret.
ok. shhhhh
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
CPallini wrote: Because we should keep it secret
But now you've let the cat out of the bag!!! The boys'll be round to sort you out
|
|
|
|
|
It's only me....I won't tell anyone!
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Wow the cat is out, hence is alive: we should tell to Mr. Schroedinger...
(or is the above another secret?)
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]
|
|
|
|
|
|
Excellent! Thank you
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
You are required to implement a C preprocessor. The Preprocessor is to be implemented as a command-line tool, the input to which is a C source file (.c extension) and the output is the preprocessed file (.i extension). The tool also takes several options.
$ cppr <options> file.c
On successful processing, file .i is produced.
<options> may be:
Preprocessor options-
-Aassertion -C -dD -dM -dN -Dmacro[=defn] -E -H
-idirafter dir -include file -imacros file
-iprefixfile -iwithprefix dir -M -MD -MM -MMD
-nostdinc –P -Umacro –undef
Directory options-
-Bprefix -Idir -I-
Implement any two of the above.
These are the options defined by the gcc compiler. You must implement the following features at a minimum:
i. Stripping off of comments
ii. #ifdef and #endif
iii. #define for constants (not macros)
COULD U PLEASE HELP ME DOING THIS PROJECT?
|
|
|
|
|
Cassendra wrote: COULD U PLEASE HELP ME DOING THIS PROJECT
I could, but 1) I dont do homework, 2) you couldnt afford me
Why dont you ask yourself some questions about
1) how you might get a program to recognise 'c' code
2) how you might use the results from (1) to perform the various tasks ..
since its almost xmas and despite doing what I thought was my last good deed of the year (84Km charity cycle on Sunday, giving blood on Wed), Im going to suggest you read these as a start :-
http://www.ibm.com/developerworks/aix/library/au-c_plusplus_antlr/index.html [^]
http://mcpp.sourceforge.net/[^]
they should give you some ideas ... you might also want to check out the posting guidelines at the top of the forum
'g'
|
|
|
|
|
Thanks for your suggestions.
MERRY CHRISTMAS.
|
|
|
|
|
I think you've got the wrong forum, jokes belong in The Lounge
|
|
|
|
|
Your is good, however.
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]
|
|
|
|
|
Ppl started posting their question papers!
|
|
|
|
|
I found a free ANSI C parser with source code - Gold Parser[^]. You could download the source as well. You can look at the source and tune it for a preprocessor and generate the .i file. I hope it will be useful for you.
Regards,
Jijo.
_____________________________________________________
http://weseetips.com[ ^] Visual C++ tips and tricks. Updated daily.
|
|
|
|
|
Hi All,
I am porting a VC++ 6.0 to VC++ 9.0
I am getting the LNK error when i tried to pass a iterator as a function parameter.
Here is the code.
void CMemTable::TestIterator( std::list< CString >::iterator it)
{
std::list< CString >::iterator itLocal;
itLocal = it;
}
CMemTable pTable;
std::list<cstring>::iterator test;
pTable->TestIterator(test);
error LNK2019: unresolved external symbol "public: void __thiscall CMemTable::TestIterator(class std::list<class>>,class std::allocator<class>>>::_Iterator<1>)"
All suggestions are invited.
Thanks you.
|
|
|
|
|
The coded you've posted wouldn't compile - pTable is an object, but you're calling TestIterator using 'pointer to member' syntax.
I'm wondering - does the signature of the declaration of TestIterator (in the CMemTable class declaration) exactly match the signature of the method's definition?
|
|
|
|