Board index » cppbuilder » Win32 Semaphores in TThread?

Win32 Semaphores in TThread?


2007-03-13 02:21:31 AM
cppbuilder46
I assume that the Win32 Semaphore functions are implemented in TThread? I've had
great success relying on Borland objects in the past for low-level routines
which I don't understand. :) Threads is certainly one of those, though I
understand the idea, I don't understand the implementation. Could I just use a
TThread instead of calling BeginThread on my own? Will all my problems go away?
(One can only hope!) I realize I'm still going to be susceptible to
non-thread-safe calls by thirdparty DLLs. I just need to eliminate all
possibilities within my power.
Thanks,
Rob
 
 

Re:Win32 Semaphores in TThread?

Robert G. Hoover wrote:
Quote
I assume that the Win32 Semaphore functions are implemented in TThread?
No they aren't. You'll still have to use the Win32 functions directly.
Quote
I've had great success relying on Borland objects in the past for
low-level routines
which I don't understand. :) Threads is certainly one of those, though I
understand the idea, I don't understand the implementation. Could I just
use a
TThread instead of calling BeginThread on my own? Will all my problems go
away?
No, your code is almost the same as what you'd use with TThread.
Jon
 

Re:Win32 Semaphores in TThread?

Jonathan Benedicto wrote:
Quote
Robert G. Hoover wrote:
>Could I just use a TThread instead of calling BeginThread on my own?
>Will all my problems go away?

No, your code is almost the same as what you'd use with TThread.
But don't you want the MainThread to do the drawing since it owns the
canvas?
That's why I mentioned TThread::Synchronize( &Display );
 

{smallsort}

Re:Win32 Semaphores in TThread?

Bob Gonder wrote:
Quote
But don't you want the MainThread to do the drawing since it owns the
canvas?
That's why I mentioned TThread::Synchronize( &Display );
No, because that would penalize the speed. Ideally, the video thread should
perform the rendering, you just can't use SetDIBitsToDevice as it is not
thread-safe.
Jon
 

Re:Win32 Semaphores in TThread?

"Jonathan Benedicto" < XXXX@XXXXX.COM >wrote in message
Quote
Bob Gonder wrote:
>But don't you want the MainThread to do the drawing since it owns the
>canvas?
>That's why I mentioned TThread::Synchronize( &Display );

No, because that would penalize the speed. Ideally, the video thread
should perform the rendering, you just can't use SetDIBitsToDevice as it
is not thread-safe.
Depends on where the speed is needed. If processing speed is more important
than rendering speed, then an alternative to Synchronize would be to have
the processing thread post 'render' messages to the message queue and let
the main thread process those messages (and perform the rendering) whenever
it can. This would allow the grabbing/processing thread to perform as fast
as possible while still allowing rendering to occur in the main thread
without resorting to a Synchronize call.
- Dennis