Gyannea
May 18th, 2004, 08:54 AM
I think I have a critical section type of problem but I am not sure. I have a couple of threads which use the GUI to draw things to various windows. Currently, I have placed critical sections around blocks of code that perform the drawing. I have tried (as much as possible) to minimize the entrance and exit of these critical sections, and usually have one entry and exit in a drawing loop.
Doing such corrected problems I was having until I recently introduced fonts into the code. Using fonts and formtting them involves calls to functions that get text lengths and things like that but no actual drawing is performed. So one does a lot of formatting garbage and then does the drawing.
The drawing is in a critical section but the formatting code is not. However, the formatting functions like
GetTextExtentPoint32(
label.hdc, // handle to device context
ptr, // pointer to text string
x + 2, // number of characters in string
&fontsize); // pointer to structure for string size
involve device contexts, and therefore calls to
SelectObject(label.hdc, label.hfont);
and things like that. I am wondering if these functions also need to be in a critical section. Doing so would greatly lengthen the time of the critical section, but I am wondering if conflicts are arising since a thread calls the drawing function and so does a Window callback procedure. They both draw to the same window, but different fonts can be used. Can one set a device context in the thread and then have the Window's callback call the drawing function with the thread's device contect setting?
I guess what I am trying to find out is which GUI functions need to be contained in the critical section.
If all of those device function need to be included, then it is probably necessary to include the entire setting and drawing in a single critical section...from the first "SelectObject' to its release.
Yuulk.
Brian
Doing such corrected problems I was having until I recently introduced fonts into the code. Using fonts and formtting them involves calls to functions that get text lengths and things like that but no actual drawing is performed. So one does a lot of formatting garbage and then does the drawing.
The drawing is in a critical section but the formatting code is not. However, the formatting functions like
GetTextExtentPoint32(
label.hdc, // handle to device context
ptr, // pointer to text string
x + 2, // number of characters in string
&fontsize); // pointer to structure for string size
involve device contexts, and therefore calls to
SelectObject(label.hdc, label.hfont);
and things like that. I am wondering if these functions also need to be in a critical section. Doing so would greatly lengthen the time of the critical section, but I am wondering if conflicts are arising since a thread calls the drawing function and so does a Window callback procedure. They both draw to the same window, but different fonts can be used. Can one set a device context in the thread and then have the Window's callback call the drawing function with the thread's device contect setting?
I guess what I am trying to find out is which GUI functions need to be contained in the critical section.
If all of those device function need to be included, then it is probably necessary to include the entire setting and drawing in a single critical section...from the first "SelectObject' to its release.
Yuulk.
Brian