|
Hi, everyone!
I have two samples on CRITICAL_SECTION, I want to know
the difference between them.
Sample 1:
--------
CRITICAL_SECTION cs;
EnterCriticalSection(&cs);
//code block1
LeaveCriticalSection(&cs);
EnterCriticalSection(&cs);
//code block2
LeaveCriticalSection(&cs);
--------
Sample 2:
--------
CRITICAL_SECTION cs1;
CRITICAL_SECTION cs2;
EnterCriticalSection(&cs1);
//code block1
LeaveCriticalSection(&cs1);
EnterCriticalSection(&cs2);
//code block2
LeaveCriticalSection(&cs2);
--------
I think in sample 1, code block 1 and code
block 2 can not be executed simultaneously.
But I sample 2, code block 1 and code
block 2 may be executed simultaneously.
Am I correct?
Thanks in advance,
George
|
|
|
|
|
George2 wrote:
CRITICAL_SECTION cs1;
CRITICAL_SECTION cs2;
EnterCriticalSection(&cs1);
//code block1
LeaveCriticalSection(&cs1);
EnterCriticalSection(&cs2);
//code block2
LeaveCriticalSection(&cs2);
hi george
EnterCriticalSection() is a blocking function, that will only returns when the calling thread get the ownership.your examle code doesnot excecuet simultaniosly
If u wanna that
use TryEnterCriticalSection() API, that will returns immediatly
~CodeTheDreams~
|
|
|
|
|
Thanks, Renjith pal!
In such case,
1. Thread 1 enters code block 2, before it leaves code block 2,
for some reason, it sleeps;
2. Thread 2 enters code block 1;
3. for some reason, thread 1 wakes up and run code block 2,
So in my case, code block 1 and code block 2 could run simultaneously.
Am I correct? But in my sample 1, such case would not happen.
I am not sure about my two samples, so I want to listen to others.
Thanks in advance,
George
|
|
|
|
|
George2 wrote:
But I sample 2, code block 1 and code
block 2 may be executed simultaneously.
In different threads, yes.
It's like a mutex with a twist - you can reenter an already entered critical section from within the same thread.
|
|
|
|
|
Thanks, Mike pal!
Do you mean my original opinion about two cases
are correct?
Cheers,
George
|
|
|
|
|
yes (i.e. yes it's correct, and yes I guess that is what Mike means)
The main difference between a mutex and a critical section is that a CS is bound to a process, while a mutex can be used cross-process.
It's a royal pain to watch a sex drugs and rock'n'roll design decay into an aids crack and techno implementation [sighist] [Agile Programming] [doxygen]
|
|
|
|
|
Thanks, peterchen pal!
George
|
|
|
|
|
My program gets the following error sometimes under Window Me.
-----------------------------------------
Inaccurate System Timer
Restart after reset of system timer
Press Enter to End.
-----------------------------------------
Is there an explanation why this happens?
Thanks in advance.
Edwin Geng
|
|
|
|
|
Edwin, you need to post more information. Is this a message from your application? Is it a message from the operating system? What happens if you press Enter? What are the circumstances when you get the error, and when you don't get the error?
Software Zen: delete this;
|
|
|
|
|
Why do I get this error how do I correct it?
I looked in the help files and tried their suggestiong, but they didn't work.
Thanks...!
|
|
|
|
|
La doc nous dit que :
Static Library Versions Library Description
NAFXCW.LIB Release version
NAFXCWD.LIB Debug version (default)
UAFXCW.LIB Release version with Unicode support
UAFXCWD.LIB Debug version with Unicode support
Il faut la version PRO de Visual Studio pour compiler en Static
|
|
|
|
|
Windows ME
Visual C++ 6.0
Hi!
I need to get/set the attibutes and date/time of directories.
I tried the win32 functions GetFileTime & SetFileTime. For this functions I need a handle to the directory.
HANDLE handle = CreateFile(
"C:\\TEMP",
GENERIC_READ, //for GetFileTime
0, //don't share
NULL, //no SECURITY_ATTRIBUTES
OPEN_EXISTING,
FILE_NORMAL, //also tried FILE_ATTRIBUTE_DIRECTORY
//and & FILE_FLAG_BACKUP_SEMANTICS
NULL);
I always get INVLID_HANDLE_VALUE, GetLastError returns 5.
How to get a handle in Win 95-98?
Thanx
|
|
|
|
|
Peppe wrote:
FILE_FLAG_BACKUP_SEMANTICS
Isn't that an NT-only flag?
If so, I believe you have to resort to the old DOS-ish INT 21h interface ("documented" in MSDN) - no promises that what you want to do is supported there though.
|
|
|
|
|
Hi,
since I'm not vey dedicated to GUI programming and it is in some cases necessary, I was seeking the way to make GUI in my applications faster, which I was writting directly through API, but not to use any RAD tool.
I started to learn MFC which is very (not to say hard ) opaque to me, maybe because I used to do programming in API directly or something else.
Friend of mine, suggested me to use WTL to make GUI faster, which is (in his opinion, I don have one yet ) much better in any aspect regarding MFC.
So, I've downloaded WTL 7.0 from MS site, but not to count add-in wizard in VC I don't know where to start from, for learning to do programming using this library. I've found one .chm file on this subject but it was corrupted, and nothing else.
So my question is, can anyone help to get start, firstly by informing me where can I find some good free documentation on this subject and a good tutorial to understand better WTL and to begin my programming very soon independantly.
Thanks.
|
|
|
|
|
try this :
http://perso.wanadoo.fr/laurent.kempe/technical/wtl/
|
|
|
|
|
When the dialog's OnInitDialog() function is called I spawn a new thread to copy a bunch of files to the drive. When the new thread is finished copying the files to the drive I want it to close itself. I made a pointer the the current dialog, and when I use it in win98 it works fine. In Win2K it says that the program created errors.
Is there a different way to close a dialog from a separate thread?
SAVAGE KEN
|
|
|
|
|
Post a message from the worker thread to the dialog (IDs starting at WM_APP are reserved for apps to use as message IDs, so use WM_APP ). When the dialog receives that message, it can call EndDialog() or DestroyWindow() depending on whether it's modal or modeless.
--Mike--
Looks like I picked the wrong week to stop sniffing glue.
1ClickPicGrabber - Grab & organize pictures from your favorite web pages, with 1 click!
My really out-of-date homepage
Sonork-100.19012 Acid_Helm
|
|
|
|
|
How can I cast the fccHandler from an Avi to a four character code/string?
|
|
|
|
|
If you've got a DWORD 'DIV3' (or whatever) you can't just cast it. To get a C zero terminated string you also need a terminating null.
Depending on host byte order you could even get away with
char sz[5];
*(long*)sz = *fccHandler;
sz[5] = '\0';
but the only portable solution is to extract the bytes one by one from the DWORD, add them to an (at least) 5 chars large char array, and end it with a zero char.
|
|
|
|
|
Thanks and forgive me for sounding stupid but there are wide gaps in my c++ knowledge so I will ask you another question. MSDN states DWORD to be 32 bit unsigned int. How exactly would I go about extracting bytes from a DWORD? Would I treat it like say an array and use a for loop: eg:
for (int iLoop = 0; iLoop < 4; iLoop++)
sz[iLoop] = fccHandle[iLoop];
In fact now that I think about it my knowledge of working with bits is actually also zero, something I've been avoiding but now it's time to learn. Can you suggest a book or a good tutorial on bit manipulation? Thanks again.
|
|
|
|
|
georgiek50 wrote:
you suggest a book or a good tutorial on bit manipulation?
If I'm not completely mistaken there's an article on this very subject right here at CP. I can't remember neither the name of the article, nor the author though. Maybe someone else remembers? In the meantime you might try browsing the articles.
|
|
|
|
|
|
|
I currently have a tree set up and when you the selction is changed it opens a dialog that corresponds with what you clicked. How can I make it so it opens when you double click an object and it doesn't necessarily have to have changed? (Example I click "General" and then I close it but I want to open "General" again without changing back and forth)
EDIT: Nevermind. I found it
|
|
|
|
|
Handle the NM_DBLCLK notification.
--Mike--
Looks like I picked the wrong week to stop sniffing glue.
1ClickPicGrabber - Grab & organize pictures from your favorite web pages, with 1 click!
My really out-of-date homepage
Sonork-100.19012 Acid_Helm
|
|
|
|