home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.os.ms-windows.programmer.win32
- Path: sparky!uunet!microsoft!hexnut!andrewgo
- From: andrewgo@microsoft.com (J. Andrew Goossen)
- Subject: Re: multiple threads per window?
- Message-ID: <1992Sep14.045409.14441@microsoft.com>
- Date: 14 Sep 92 04:54:09 GMT
- Organization: Microsoft Corporation
- References: <1992Sep13.012441.5140@microsoft.com>
- Lines: 40
-
- In article <1992Sep13.012441.5140@microsoft.com> johnhall@microsoft.com (John Hall) writes:
- >In article bagwill@swe.ncsl.nist.gov (Bob &) writes:
- >| If I wanted to write an application which used multiple threads
- >| to draw a fractal in a window, which mechanisms should I use to
- >| avoid screwing up the drawing?
- >
- >That depends. If they are drawing on different portions of the
- >screen (each thread takes a 1/4 slice of the window) then you
- >need do nothing. If the drawing is order dependent to the
- >same pixel locations then take your pick:
- > semaphores, mutex's, critical sections, event's
-
- GDI objects are shareable between threads in a process; however,
- an object may be used by at most one thread at any one time.
- For example, if two threads make GDI calls to the same DC
- at the same time, GDI will return an error to the second thread.
-
- So it's up to the app to synchronize its use of GDI objects, using
- whatever of the many synchronization mechanisms that NT provides
- that they like.
-
- In the above example, only if the app had split the screen into
- different DC's covering distinct sections of the window, with each
- thread responsible for one DC, would the app not need to do
- synchronization with respect to GDI.
-
- A better design is to have one thread doing all the drawing to
- a DC, and the other threads doing the drawing computations.
- Another way is to have multiple threads simultaneously constructing
- a bitmap, and BitBlt the result when it's done.
-
- It would be nice to allow threads to do true simultaneous drawing on
- a device. Unfortunately, at some level all device access must be
- serialized; things like hardware state and asynchronous pointer
- movement requires this.
-
- While GDI objects are shareable between threads in a process, they
- are not generally shareable between different processes.
-
- andrewgo@microsoft.com GDI person
-