|
If you only read the variable, you don't need to synchronize anything
If you simultaneously read and write to the variable, only the writing operation should be interlocked.
Robert-Antonio
"Life is very hard, when you apply E-R model to it."
|
|
|
|
|
Thanks for your answer, but in the MSDN Library I found the following sentence:
Simple reads and writes to properly-aligned 32-bit variables are atomic.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/interlocked_variable_access.asp
What about other variables like char (8bit)? Isn't it possible, that during the read process another thread writes to the variable with InterlockedExchange. After this the read thread is reading the second part of the variable. It gets corrupted, because it wasn't an atomic read. What about other variables like 8, 16 bit. Are reads always atomic?
And do I need volatile for these variables if I write to them only via InterlockedExchange.
Thanks for any answer
Konrad
|
|
|
|
|
You do not need to use volatile if using InterlockedExchange.
Reads/writes to/from 8 bit values are atomic on x86 platforms.
Do note that if you must guarantee a specific sequence of reading and writing, you'll need to use more complex synchronization methods.
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
|
I think you're right. 8- and 16-bit writing should be atomic too. The operation is made by only one assembler instruction MOV.
Volatile declaration is necessary, because it tells to compiler, that its value may be changed every time by another thread. For example, if you're referring to the variable multiple times in one thread, the compiler should optimize it by storing its value in register. If another thread changes the value, you have a different value in memory and register and the program could not behave correctly. Volatile declaration ensures, that the value of variable is always taken from the memory.
Robert-Antonio
"Czech Railways discovered, that in case of disaster the most damaged wagons
were the first and the last. So they decided to create trains without them."
|
|
|
|
|
Hi,
I want to open & display a file(ex: .C) with Line Number to be displayed infront of each line. (Ex: Like C Debugger have)
Plz. send me code if anybody written...
irshad_b@indiatimes.com
Thanks in Advance,
Regards,
Irshad
|
|
|
|
|
I know how to do it, but i am not going to write a code for you.but hey how lazy can you get?
P.R.A.K.A.S.H
|
|
|
|
|
Assuming you have an edit control with the ES_MULTILINE style, you can do something like:
CStdioFile file(_T("c:\\boot.ini"), CFile::modeRead);
CString strFileLine,
strEditLine;
int nLine = 1;
while (file.ReadString(strFileLine) != FALSE)
{
strEditLine.Format(_T("%d %s\r\n"), nLine++, (LPCTSTR) strFileLine);
m_edit.ReplaceSel(strEditLine);
}
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
Thanks for ur reply..
Sorry i am asking silly questions..as I am new to MFC...Actually i want to
1. open C source file with standard coloring of keywords of C langauge ..&
2. a new view window which display line number & have capabilty to set break-points ..(like M VC++ editor have)
3. a shared vertical scroll-bar between these windows.
I am using RichEditView class for other operations like get line number on double-clk,etc..
Regards
Irshad
|
|
|
|
|
what is the best way to debug a service in vs 6.0..
|
|
|
|
|
Is the service writen by you??
If yes set the breakpoints and press f5
P.R.A.K.A.S.H
|
|
|
|
|
There are a few ways really. Normal Breakpoint F5 debugging is tricky as im sure you have found out due to the way the SCM starts the service.
I usually write my app as a normal app then turn it into a service when its done, but if thats not possiable you can use hardcoded breakpoints
Put the line "_asm int 3" into your service's code and you find when you run the service you get a dialog asking you to debug the app. Press cancle and you will be taken into the debugger
|
|
|
|
|
hello,
I want to prevent user shutdown.
I am catching the WM_QUERYENDSESSION message and returning a 1, which occording to the
inline help should stop the shutdown process.
It works on occassions but crashes on others, it seems to be completely inconsistent too...I know i am cathing the WM_QUERYENDSESSION so its not anything else...
Is there something else I need to do???
Thanks in advance
|
|
|
|
|
rw104 wrote:
I am catching the WM_QUERYENDSESSION message and returning a 1, which occording to the
inline help should stop the shutdown process.
I believe that should be a 0.
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
rw104 wrote:
I am catching the WM_QUERYENDSESSION message and returning a 1, which occording to the inline help should stop the shutdown process.
Hum, I don't get the same info in MSDN:
From MSDN, Platform SDK: Windows System Information
"Return Values
If an application can terminate conveniently, it should return TRUE; otherwise, it should return FALSE.
Remarks
By default, the DefWindowProc function returns TRUE for this message.
Windows NT/2000/XP: When an application returns TRUE for this message, it receives the WM_ENDSESSION message and it is terminated, regardless of how the other applications respond to the WM_QUERYENDSESSION message.
Windows 95/98/Me: After all applications return TRUE for this message, they receive the WM_ENDSESSION and they are terminated. "
HTH,
K.
And I'm talking to myself at night because I can't forget
Back and forth through my mind
Behind a cigarette
|
|
|
|
|
Hi!
I'm about to learn mfc so for the moment I'm just playing around. I'm trying to create a plain window using the CFrameWnd class. The Create funtion takes a parameter called lpszMenuName. msdn gives the following explanation:
lpszMenuName
Identifies the name of the menu resource to be used with the window. Use MAKEINTRESOURCE if the menu has an integer ID instead of a string. This parameter can be NULL.
So my question is: How do you identify a menu resource with a string instead of a integer ID. Also, MAKEINTRESOURCE gives me a compile error.
|
|
|
|
|
What is the project type that you have selected?
P.R.A.K.A.S.H
|
|
|
|
|
1. How to identify a menu resource with a string instead of an integer ID.
Simple. Don't #define the symbol you use, eg MYMENU, to have an integer value.
In the absence of other information, this will be treated as a string name.
Note, however, that if you're using the VC++ IDE, it will automatically define a number for you, so it's harder to do this - you have to remember to type quotation marks &dquot; around the name.
2. You are using something like
MAKEINTRESOURCE( mynumber )
or
MAKEINTRESOURCE( 12 )
aren't you?
Steve S
|
|
|
|
|
|
and yes, I'v been using MAKEINTRESOURCE as you decribed. Is there another way?
|
|
|
|
|
No, but I have seen people use:
::LoadMenu(hInst, MAKEINTRESOURCE);
and wonder why it doesn't compile
Steve S
|
|
|
|
|
How to get HDD serial number from Windows98?
were rgrtgrtvrtrt rtrtb brt tyuhjghj hbhbnh hnjm 1234567?
|
|
|
|
|
|
thanks,
but not the volume serial number on the partition.
i mean the fabric serial number on the phisical hard drive.
were rgrtgrtvrtrt rtrtb brt tyuhjghj hbhbnh hnjm 1234567?
|
|
|
|
|
|
Hi,
I have maid a ATL Modeless DialogBox for an add in in VS.NET and I have some problems with backspace end Delete keys: when I use my dialog Box and if I have opened some file before, I can enter text in the edit boxes but if I use the backspace key, I will erase text in my files not in the dialog box!
How can I set the focus on my dialog box for these key inputs?
|
|
|
|