Article View: borland.public.cppbuilder.nativeapi
Article #13618Re: Thread synchronisation
From: Rob
Date: Tue, 30 Sep 2003 10:54
Date: Tue, 30 Sep 2003 10:54
29 lines
2334 bytes
2334 bytes
"Wim Bekker" <wim@bekker> wrote in message news:3f77f4b0@newsgroups.borland.com... > > "Remy Lebeau (TeamB)" wrote: > > No. Use Synchronize() to access the Canvas. > > > > Preferably, anything related to the GUI should be done in the main thread. > > Thanks Gambit. For most part I will not use the Synchronize method as it > could halt the thread until the main-thread handles the request. Instead, I > copy all needed values into a thread-safe place and signal the main thread > that there's info available (PostMessage). This works perfectly and allows > the heavy duty thread to perform best. > This is a good technique; it's one I've used regularly. One potential issue to be aware of is ensuring that the worker thread does not access the "needed values" while the main thread is using them. I presume this is what you mean by a "thread-safe place" eg the needed values are protected by a critical section. There is a slight performance overhead with this (it is just a cost of preventing things like race conditions). Your statement about the Synchronize() method needs to be stronger: it *will* halt the worker thread until the main thread handled the request. That is the whole purpose of the method.
Technical Details
Message-ID:
<3f796747@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!sn-xit-02!sn-xit-04!sn-xit-01!sn-xit-09!supernews.com!wn14feed!wn13feed!wn11feed!worldnet.att.net!216.166.71.14!border3.nntp.aus1.giganews.com!border1.nntp.aus1.giganews.com!nntp.giganews.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mailReferences:
<3f704989@newsgroups.borland.com> <3f750c0d$2@newsgroups.borland.com> <3f77f4b0@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10cc67,20b65b563d927a2d X-Google-Attributes: gid10cc67,public X-Google-ArrivalTime: 2003-09-30 04:48:10 PST From: "Rob" <nospam@nonexistant.com> Newsgroups: borland.public.cppbuilder.nativeapi References: <3f704989@newsgroups.borland.com> <3f750c0d$2@newsgroups.borland.com> <3f77f4b0@newsgroups.borland.com> Subject: Re: Thread synchronisation Date: Tue, 30 Sep 2003 20:24:53 +0930 Lines: 31 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4807.1700 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300 NNTP-Posting-Host: 211.26.115.2 Message-ID: <3f796747@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1064920903 211.26.115.2 (30 Sep 2003 04:21:43 -0700) Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!sn-xit-02!sn-xit-04!sn-xit-01!sn-xit-09!supernews.com!wn14feed!wn13feed!wn11feed!worldnet.att.net!216.166.71.14!border3.nntp.aus1.giganews.com!border1.nntp.aus1.giganews.com!nntp.giganews.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail