When I use _beginthread() to create the worker, the program works.
However, whenever the worker thread runs, the GUI becomes slow, and
the mouse movements are choppy.
My idea was to use SetThreadPriority() to lower the priority of the
worker thread. However, it requires a thread HANDLE returned from
CreateThread(). _beginthread() returns a different type of handle.
My understanding is that CreateThread() cannot be used if standard C
runtime libraries are called. This function is in a DLL, uses many
standard C library calls, and also uses other DLL's of unknown
content.
When I tried to run the thread using CreateThread(), the thread did
not even start. I set a breakpoint at the entrance and it never gets
there.
Now for the questions:
1 - Is my basic analysis correct?
2 - Is there a function to lower a thread priority which can be used
after _beginthread()?
3 - Is there a way to convert the handle so that I can use
_beginthread() followed by SetThreadPriority()?
3 - Is there some other way to keep the GUI running smoothly
while a worker thread is running?
3 - Am I right that CreateThread() cannot be used if C runtime
libraries are called?
4 - What would cause CreateThread() to fail in such a way that
it doesn't seem to get to the first instruction.
--
Ken Goldman kg...@watson.ibm.com 914-784-7646
Dirk
You can set the worker thread priority from within the worker thread using
GetCurrentThread to get the handle. You can also control the context
switches from within the worker thread SwitchToThread or from GUI thread
by SuspendThread. If you have tight loops in the worker, you can
occasionally Sleep or switch context.
Best Regards,
Alen
ail...@esd.dl.nec.com
> You are right to use _beginthread when using C, CreateThread alone will
> cause memory leaks, but it should run nonetheless I think.
This applies only to the static-link version of the runtime. For this
and other reasons, I *highly* recommend using the DLL runtime, which
lets you use CreateThread() without prejudice.
--
Cheers,
Felix.
If you post a reply, kindly refrain from emailing it, too.
Note to spammers: fel...@mvps.org is my real email address.
No anti-spam address here. Just one comment: IN YOUR FACE!