|
A Problem with the previously mentioned algorithms is that they assume "atomic" read and write operations.
I also found this solution which is, like you say is dependent on "undividable" processor instructions.
// ALGORITHM
////////////
// wait(s)
// { set s = 0 and if old value of s was 0 then
// repeat
// 'wait'
// until set s = 0 and old value of s was 1 }
// signal(s)
// { s = 1; Tell OS if appropriate }
Concerning, "how are you getting multiple threads if you don't have an OS?".
From my perspective (WinNT/W2K backend programmer, now engaged in building software for a NO-OS device), the device we are building has two "tasks" ("Threads").
It has a slow main loop (task 1) which can be 'interrupted' ("pre-empted") by the driver level (task 2..N).
The idea is to have the driver level handle the Hardware dependent stuff, e.g. detect if a keypad button that was pressed, and put it in an event queue for the slow main loop to process.
If my main loop can get interrupted at any time, I need some protection (locking) on the queue, otherwise it will get corrupted. (if it is locked by the main loop, I could put the event in a temporary queue and put it in the real queue some time later (ASAP of course) )
The standard way of avoiding corruption is:
mutex_begin()
{
disable_interrupts();
}
mutex_end()
{
enable_interrupts();
}
Which of course could lead to "event loss".
The algorithm above (based on TestAndSet) is an improvement over this, but it needs to be supported by processor instructions.
Since I am not a whizz kid in assembler (let's be honest, I never had to use it before so I never did), I am gratefull for any pointers or assembler crash courses that anyone can give me about these undividable SMP safe (i386) instructions I could use to implement a Test And Set function.
// MSDN example
int power2( int num, int power )
{
__asm
{
mov eax, num ; Get first argument
mov ecx, power ; Get second argument
shl eax, cl ; EAX = EAX * ( 2 to the power of CL )
}
/* Return with result in EAX */
}
// my would-be function that sets a value (nValue) on the target address (pTargetAddress) and returns the previous value (that was found in pTargetAddress)
int testandset(int* pTargetAddress, int nValue)
{
__asm
... // help !
}
Best regards,
Gert.
|
|
|
|
|
I think this is it, unless I'm mistaken.
int TestAndSet(int* pTargetAddress, int nValue)
{
__asm
{
mov edx, dword ptr [pTargetAddress]
mov eax, nValue
xchg eax, dword ptr [edx]
}
}
|
|
|
|
|
Anyone know of any good face recogition software? I've got two bitmaps, and I'd like to compare them to see if they are the same person.
|
|
|
|
|
Hello!
I have been trying to set the color of a slider I created with MFC. I managed to color it's background but didn't manage to change the slider "knob" or "path" color, how is this done?
I also have a Combobox wich I would like to change the color of as well, but it didn't work out either. I tried to check the "owner drawn and with strings on the Combobox, but I still couldn't change the colors and over the text was the picture of my icon, hmm...
Then there's the frame of the window, I beieve I should override OnNcPaint() function for this but either I'm wrong or doig it wrong. =)
And changing the color of the entire application menu would be very nice if I could do this too.
I tried to override OnPaint, but it didn't work... I could use some samples of code, since I seem to be doing something wrong when I don't get it to work. =) I heard something about "changeing the thumb and track colors using custom draw." how is this done in code?
Thanks,
/Fredrik
|
|
|
|
|
Try
http://www.codeproject.com/miscctrl/cfctrl.asp
Not exactly what you want, but you could work from here...
HTH
Jerry
|
|
|
|
|
Thanks, that helped with the colors in the ComboBox, but my real problem is the color of the little thin line around the ComboBox and the little arrow for klicking on the combobox to bring down the choices in it. Does anyone know how to override the dialog from getting these colors from the system and how to set them? I have tried a lot of things but none seems to work.
Also, how to paint the frame of the dialog window and how to override the menu colors, not just the fields in the menu, but I want contol over the whole menu and what color it has.
I really need help with this, this problem is really killing me!
|
|
|
|
|
Simple just paint over it!
Have a look here...
http://www.codeproject.com/combobox/combobox_flatcombo.asp
HTH
Jerry
|
|
|
|
|
I have a dialog-based application. I would like to hide the main dialog and display an icon only in the system tray. I've tried to use ShowWindow(SW_HIDE), but the dialog still appears.
In "ApplicationName.cpp" file and in "InitInstance" module, my codes look like the following:
CFwuTestDlg dlg; //1 //the main dialog
m_pMainWnd = &dlg; //2
m_pMainWnd->ShowWindow(SW_HIDE);//3
m_pMainWnd->UpdateWindow();//4
int nResponse = dlg.DoModal();//5
return FALSE;//6
I've tried to delete line 5, but Windows complains that .exe file generate error.
Could anyone help me? Thank you.
|
|
|
|
|
First, you do not need to hide the dialog. The way that the system tray works is that windows are minimized to be not shown.
http://www.codeproject.com/shell/systemtray.asp
http://home.socal.rr.com/samhobbs/VC/TaskbarStatusIcon.html
You certainly do not want to remove the DoModal (line 5) but you do want to remove the ShowWindow and UpdateWindow (lines 3 and 4).
|
|
|
|
|
Is it possible to store pointers to objects in the STL collection classes and have the collection automatically destroy the objects as the collection elements are destroyed? e.g.:
class A
{
int var1;
};
vector<a*> v;
A* obj1 = new A;
A* obj2 = new A;
v.push_back(obj1);
v.push_back(obj2);
v.clear();
The last statement here will remove all elements from the vector but won't delete the actual objects, *obj1 and *obj2. Can vector be specialised so it will delete the objects its elements point to? (This can be done fairly easily in MFC so I am hoping the same is true for STL)
|
|
|
|
|
No. It's not possible, at least not without modifying the STL classes (which you shouldn't do anyways, since people will expect their behavior to be consistent with what the standard dictates).
Just write a small for loop which iterates over the pointers and delets them, then call clear. Or, don't store pointers in your vector, but the actual objects themselves.
|
|
|
|
|
No. It's not possible, at least not without modifying the STL classes (which you shouldn't do anyways, since people will expect their behavior to be consistent with what the standard dictates).
Just write a small for loop which iterates over the pointers and delets them, then call clear. Or, don't store pointers in your vector, but the actual objects themselves.
|
|
|
|
|
No. The trick is not to specialize the container, but to specialize the pointers you store in the container.
Use smart pointers in the collection instead of ordinary pointers.
A smart pointer will delete the object it points to, if the smart pointer gets deleted. Otherwise it behaves just like an ordinary pointer.
A smart pointer implementation that can be used as STL container element can be found at http://www.boost.org. Just look there for the class shared_ptr in the smart_ptr library.
|
|
|
|
|
I'm having trouble finding information on how to customize the Windows file open dialog to add, for example, a preview pane for images or something like that. I know I have to subclass the common dialog and I've found a few simple examples but nothing like adding other controls to the dialog. Can anyone point me to any resources or give me a general idea what I need to do? Thanks in advance.
Cheers,
Farzad
|
|
|
|
|
I want to know if I press a icon on the Toolbar, how can I run the code??? I mean like if I click a icon, and what I want to do is run a function!!!! How?
Thanks
|
|
|
|
|
Here's a link to an MSDN document to get you started.
|
|
|
|
|
Hey any one know how to get the size of the Single Document?? When the user resize the Form I want to know what's the length and width of the resized form!!! Thanks for anyone that helps!!!!!
|
|
|
|
|
If you're talking an SDI app, AfxGetMainWnd()->GetWindowRect() will do it.
|
|
|
|
|
AfxGetMainWnd()->GetWindowRect() will get the size of the frame, not the view.
|
|
|
|
|
How do I get the icon from a running process?
I already have the Process ID, the hwnd, and the hinstance of the runnig program, and I want to get the icon of that process and display it in a list control and in a dialog tab.
I could get the executable filename too, but I'd like to avoid that if possible.
Many thanks in advance.
|
|
|
|
|
How do I get the icon from a running process?
I already have the Process ID, the hwnd, and the hinstance of the runnig program, and I want to get the icon of that process and display it in a list control and in a dialog tab.
I could get the executable filename too, but I'd like to avoid that if possible.
Many thanks in advance.
|
|
|
|
|
How do I get the icon from a running process?
I already have the Process ID, the hwnd, and the hinstance of the runnig program, and I want to get the icon of that process and display it in a list control and in a dialog tab.
I could get the executable filename too, but I'd like to avoid that if possible.
Many thanks in advance.
|
|
|
|
|
Does anyone know where I can find a tutorial or book for Adobe Premiere SDK? I looked at the documentation by Adobe and it seems a little bit on the high-level. Specifically, I want to know how to make plug-ins.
-- Frank
|
|
|
|
|
Can someone help me? I need to set my Dialog Box to a certain size on initialization, so that it will be proportionate to the computer screen it is ran on? Right now it opens at different sizes on different computers. Is it a resolution problem, or do I need to check Desktop window size during initialization? I would appriciate any info. Thank You
|
|
|
|
|
It's not a problem at all, dialogs have a fixed size. It "looks smaller" on 1280x1024 than 800x600 because there's more screen there.
To change the dlg size, call CWnd::SetWindowPos() at the end of your OnInitDialog() . But you'll need to resize/reposition all your controls as well, or the dlg will look fugly.
|
|
|
|