|
No, after you have read data...you will need to close the handle, reopen it and call SetupComm() before reading/writing.
Best Wishes,
David Delaune
|
|
|
|
|
Thanks!
36. When you surround an army, leave an outlet free.
...
Do not press a desperate foe too hard.
SUN-TZU - Art of War
|
|
|
|
|
Hello,
can I somehow find out how many thread are waiting
for an event on WaitForSingleObject (or how many Threads
have been released when setting it?
Alex
|
|
|
|
|
WaitForSingleObject waits for only one object. And to know the state of a thread, use getExitCodeThread.
OK,. what country just started work for the day ? The ASP.NET forum is flooded with retarded questions. -Christian Graus
Best wishes to Rexx[^]
|
|
|
|
|
Thank you for your answer.
VuNic wrote: WaitForSingleObject waits for only one object.
But multiple threads can wait for one object - and I would like to know how many. The problem is:
when I use a (synchronized) counter before the WaitForSingleObject,
how do I know if the Thread has already reached it and is waiting
or was interrupted before - I can not unlock the counter atomically
with the WaitForSingleObject call...
Alex
|
|
|
|
|
LionAM wrote: how do I know if the Thread has already reached it and is waiting or was interrupted before
There's no way reliably. What thread would be examining this thread to see where it's at?
What are you trying to do and how is this counter involved? There may be a simpler solution
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I wanted to implement a multiple reader/single writer lock.
The counter counts the number of waiting readers (which
then wait until the event is set).
If a writer unlocks, it sets (or pulses if there are writers
waiting) the event so that all waiting readers can resume -
but only if they already wait.
Alex
|
|
|
|
|
The lack of an atomic lock/counter-adjust API makes it tricky.
There's a ton of solutions on the web (e.g. search "reader writer lock") that vary in performance and whether
they favor the reader thread(s) or the writer thread(s).
Even if you're looking to design your own, they're worth looking at IMO.
Here's an interesting article: Implementing a Reader-Writer lock[^]
along with its companion article: Analysis of Reader-Writer lock[^]
Here's a simple example - straight forward, if performance isn't a major concern: Reader/Writer Lock[^]
Hope that helps a bit,
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I have found a very simple and short solution, using only
two "fast critical sections" (interlocked bool) and one
(interlocked) counter - and less than 20 lines of code.
Alex
|
|
|
|
|
Cool!
As long as it meets your performance requirements and doesn't deadlock
Like I mentioned, there's lots of ways to do it - with "big" performance differences between
the solutions.
Glad you found a solution!
Cheers,
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
AFAIK, no, not with Windows synchronization objects.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Friends, I am working on the code, wrote by somebody.. I added a new menu Item in the resource.. say "xyz", during the
runtime it is shown as "@xyz@".. I need it as "xyz",
how to handle this friends..
|
|
|
|
|
ptr_Electron wrote: how to handle this friends
Fix it friend
led mike
|
|
|
|
|
Thanks for ur responce friend
|
|
|
|
|
Did you use of ANSI code?
|
|
|
|
|
Where we can get CImage sources (UNICODE COMPATIBLE) to load GIF, JPEG in our application ?
Anyone Please help on this.
Thanks a Lot
Thanks a lot
|
|
|
|
|
The source code is included with Visual Studio.
CImage uses GDI+ to load and save images. The loaded GDI+ image is converted to a DIBsection, which is
wrapped by the CImage class.
The loading code is similar to this (without the conversion to a DIBSection):
ULONG dwToken;
Gdiplus::GdiplusStartupInput input;
Gdiplus::GdiplusStartupOutput output;
Gdiplus::Status status = Gdiplus::GdiplusStartup(&dwToken, &input, &output);
if(status == Gdiplus::Ok)
{
Gdiplus::Bitmap *pSrcBitmap = new Gdiplus::Bitmap(L"C:\\test.jpg", FALSE);
<font color="Green">
delete pSrcBitmap;
Gdiplus::GdiplusShutdown(dwToken);
}
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Actually i am sure, there is no manual for CImage, in MS Visual Studio though it is included. If so what header i need to include to proceed?
Thanks for your response!
Thanks a lot
|
|
|
|
|
atlimage.h in VS 2008 - most of it is inline.
It used to be an MFC class so it was a different header file before.
What version of Visual Studio are you using?
If you don't have a VS version that has the class, you can always use GDI+ directly, as I showed in the sample code.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
you can find it on the its header file.
|
|
|
|
|
Does anyone here know a way of using the value of a constant class member in an #if condition.
What I'd like to do for example is :-
<br />
class CSomething<br />
{<br />
public:<br />
<br />
enum<br />
{<br />
E_IsCool = 1;<br />
};<br />
};<br />
<br />
<br />
#if (CSomething::E_IsCool)<br />
#else<br />
#endif<br />
<br />
This may seem unnecessary when there is only one CSomething but I have several different ones, some cool some not and then a typedef is used to give one of them the name that is actually used. I'm trying to avoid peppering the classes with #define s and #undef s
Nothing is exactly what it seems but everything with seems can be unpicked.
|
|
|
|
|
|
Yes it would normally and I've been thinking about using it. There is one small snag though. What if the conditional code is something like this:-
<br />
#if (CSomething::E_IsCool)<br />
#define _LONG_SUFFIX(_X) _X#L<br />
#else<br />
#define _LONG_SUFFIX(_X) _X<br />
#endif<br />
I can't find any way to pull in things like this that seem to have to be macros conditionally at the moment and I'm only really sold on going the template-mp route if I can do it all that way.
Nothing is exactly what it seems but everything with seems can be unpicked.
modified on Wednesday, April 2, 2008 10:59 AM
|
|
|
|
|
Matthew Faithfull wrote: This may seem unnecessary when there is only one CSomething but I have several different ones, some cool some not and then a typedef is used to give one of them the name that is actually used
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
I was trying to keep the example simple, obviously I failed .
<br />
class CSomething<br />
{<br />
public:<br />
<br />
enum<br />
{<br />
E_IsCool = 1;<br />
};<br />
};<br />
<br />
<br />
#ifdef USE_MYSOMETHING<br />
typedef CMySomething CSomething<br />
#else<br />
#endif<br />
<br />
<br />
<br />
#if (CMySomething::E_IsCool)<br />
#define _LONG_SUFFIX(_X) _X#L<br />
#else<br />
#define _LONG_SUFFIX(_X) _X<br />
#endif<br />
<br />
This is closer to what I'm really doing which is somewhat more complicated. It has to work on different compilers as that really is the point of this so any template tricks will need to be MSVC6 friendly
Nothing is exactly what it seems but everything with seems can be unpicked.
|
|
|
|