|
Im dipping my toe into the murky waters of i/o completion ports.
My app presently use threads to handle client connections , on for each connection. Naturally i now want to use i/o completion ports.
Internally i do a lot of database access using odbc. Is there any way to link a SQLExec statement to a completion port ? Theres lots of examples of using sockets but nothing about databases. Doing an async read still involves polling to test the status of the executing statement, which will still mean using multiple threads.
I cant believe theres not support for this but ,as ever, the MS docs are very light on the subject.
Dave
|
|
|
|
|
Dave-B wrote:
Internally i do a lot of database access using odbc. Is there any way to link a SQLExec statement to a completion port ? Theres lots of examples of using sockets but nothing about databases. Doing an async read still involves polling to test the status of the executing statement, which will still mean using multiple threads.
Simple multithreading suits your application which uses SQLExec, IOCP is for overlapped reads/writes with SQL does not support.
|
|
|
|
|
Norm Almond wrote:
Simple multithreading suits your application which uses SQLExec, IOCP is for overlapped reads/writes with SQL does not support.
As you state that SQL does not support overlapped read/writes, presumabley this means that IIS etc, are not truly scallable if the script uses database access . Thats a real bummer in the real world, though as i will have to have multi threads 'hanging around' for the database to return results.
BTW thanks for your IOCP code.
Dave
|
|
|
|
|
With IOCP you have some worker-threads, normally I go for 2 - 4 four for each CPU in the machine.
If everything is running fast and not waiting for anything, your completion port only uses a single thread for each CPU, but if one of those threads is "suspended" waiting for disk I/O, a database or something else, and a new socket connection is opened, the completion port uses a new thread to handle that connection.
Basically IO Completion Ports is a mix between a threadpool and async. I/O
- Anders
Money talks, but all mine ever says is "Goodbye!"
|
|
|
|
|
I have a modal dialog box which has a tab control. During the dialog box's procedure I create three modeless dialog boxes for the display area of the different tabs. I used a common dialog box procedure for all three modeless dialog boxes (Q: Is this bad?). In the procedure for the three dialog boxes I call CreateSolidBrush for coloring the background of some controls. When I close the main (modal) dialog box I call DestroyWindow three times for each modeless dialog box. I process the WM_DESTROY message in the procedure for the three modeless dialog boxes and in it I call DeleteObject(hBrush). Does this cause a resource leak because CreateSolidBrush is called three times yet DeleteObject only once (even though it is the same handle to the brush) ?
|
|
|
|
|
Q: Is this bad?
On the contrary, it is the normal thing to do if the three dialog boxes look the same.
Does this cause a resource leak because CreateSolidBrush is called three times yet DeleteObject only once (even though it is the same handle to the brush) ?
Seems to me you're doing it in plain Win32 style, no MFC, right? If so, you're producing memory (or GDI) leaks, as there's only one copy of the HBRUSH object --previous brushes get lost on succesive calls to CreateSolidBrush . To avoid this, probably the simplest workaround is to have a count of how many instances of the dialog there are, initialize resources when the first one gets created and do the cleanup when the last one dies.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Thanks for the help, actually, I think I confused myself, I'll post the code for the modeless dialog procedure and maybe you can tell me if I am creating a resource leak or not?
This is the function for the three modeless dialogs:
BOOL CALLBACK InfoTabChildDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
HBRUSH hControlBrush = CreateSolidBrush( RGB(170, 170, 213) );
int iStaticWindow;
switch(message)
{
case WM_CTLCOLORSTATIC:
iStaticWindow = GetWindowLong( (HWND) lParam, GWL_ID );
switch(iStaticWindow)
{
case IDC_MOVIENAME:
case IDC_CATEGORY:
case IDC_STATUS:
case IDC_LOCATION:
case IDC_NUMBER:
case IDC_TITLE:
case IDC_YEAR:
case IDC_DIRECTOR:
case IDC_TAGLINE:
case IDC_PLOT:
case IDC_GENRE:
case IDC_ACTORS:
case IDC_LANGUAGE:
case IDC_RUNTIME:
SetTextColor( (HDC) wParam, RGB(0, 0, 0));
SetBkColor( (HDC) wParam, RGB(170, 170, 213) );
return (BOOL) hControlBrush;
}
return TRUE;
case WM_INITDIALOG:
return TRUE;
case WM_DESTROY:
DeleteObject(hControlBrush);
EndDialog(hDlg, 0);
return TRUE;
case WM_COMMAND:
switch(LOWORD (wParam))
{
case IDC_UPDATE:
_beginthread(IMDbThread, 0, NULL);
return TRUE;
}
break;
}
return FALSE;
}
For the modal dialog box, when I want to end everything I have I call DestroyWindow(); 3 times, one for every modeless dialog. If the previous hBrush(es) are getting lost with each successive call, then how do I go about keeping count of how many instances of the dialog I have? Also, am I correct in thinking that the WM_CTLCOLORSTATIC message gets called before WM_INITDIALOG? In that case maybe I should call DeleteObject(); in WM_INITDIALOG.
|
|
|
|
|
Well, you're having massive resource leaks here: Every time InfoTabChildDlgProc is called (and it's called many times during the life of a dialog box) you create a fresh HBRUSH . The way to have one and only one brush is by defining hControlBrush as static . Also, by combinig this fix with the count of instances hack, you'll ge the following:
BOOL CALLBACK InfoTabChildDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
static HBRUSH hControlBrush;
static unsigned int nCount=0;
...
case WM_INITDIALOG:
if(nCount++==0){
hControlBrush = CreateSolidBrush( RGB(170, 170, 213) );
}
return TRUE;
...
case WM_DESTROY:
if(--nCount==0){
DeleteObject(hControlBrush);
}
EndDialog(hDlg, 0);
return TRUE;
...
} Hope this helps, regards,
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Thanks a lot, this actually does help! I forgot about the good old static keyword. You made me a little paranoid though. In all my dialogs I have declared local variables, a lot of HWND's mostly to get a handle on controls. I don't suppose that is also creating a memory leak...right? Also, is it a good rule of thumb to declare handles that use Create... (like CreateSolidBrush) as static wherever they may be, eg. WndProc. One last question!: I am correct in thinking that WM_INITDIALOG get called once and only once, so that in my other dialogs I can call CreateSolidBrush without having to count how many instances of the dialog I have since it is only one?
|
|
|
|
|
I have two console programs. I am on a command prompt cmd.exe (fullscreen/windowed makes no diff) The simplified code is here for each program:
prog1:
main()
{
char *args[3];
args[0] = "prog2.exe";
args[1] = "abc";
args[2] = NULL;
printf("this is in prog1.\n");
_execv("prog2.exe",args);
exit(0);
}
... and prog2:
main()
{
printf("this is in prog2.\n");
getchar();
exit(0);
}
When I execute prog1, prog1 returns to the command prompt and interferes with prog2 by the input focus being on the command line. How can I keep the focus on prog2?
I can see no way around this! What can be done to keep the focus on the second running program? If I start prog1 without using cmd, it works fine, but this is not practical.
Thank you in advance ... this is driving me nuts!!!
|
|
|
|
|
Just an idea...
Try CreateProcess instead of _execv
- Anders
Money talks, but all mine ever says is "Goodbye!"
|
|
|
|
|
thanks for your response!
However, I have tried this and have gotten the same results. whether handles are inherited, etc etc I get the same results. I am amazed that no one else has run into this problem!
|
|
|
|
|
When using CreateProcess you are returned a process handle inside the LPPROCESS_INFORMATION parameter. Use this handle with WaitForSingleObject to wait for termination of prog2.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Thank you for your response...
I have considered your suggestion, but the example I have given merely simplifies a bigger problem. I have up to 175 or so different console apps which may be selected from a menu system. It does not seem practical to do this. However, I suppose a program which essentially protects all these from ever reaching the command prompt would be an option.
Wouldn't this behavior be classified as a bug? I have never seen this in DOS or OS/2.
The only other thing I can think of is thatthe command prompt uses a different in, out and error handle, but I do not see any way of determining what they are.
Is there a routine which would suspend the in and out buffers of a command prompt or any other process? There must be some way to make this behave more like a normal shell.
Thanks!
|
|
|
|
|
Maybe you can try replacing _exec with system , provided you have access to all portions of the source code where the change should be made.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
hi,
i've created a template for the open file dialog box to display a opengl scene. in the WM_INITDIALOG message, i create a thread which initialize the opengl env. my problem is that i don't see anything displayed while everything is ok (i'm doing a lot of checks).... is there something preventing the common dialog boxes to support threads ??
if you have a solution that works without thread, i would like to hear it
thanks for your help.
note : i don't use mfc.
haust
|
|
|
|
|
It is unlikely that open file dialog box should even notice that one of its controls leaves in another thread. It is my understanding that you have a window in another thread where opengl draws something, is that correct? Opengl on another hand, as understand, needed to be initialized per thread.
|
|
|
|
|
hi Alex0,
actually it works the problem was that, since the code i used was a quick cut-and-paste from another standalone modeless dialog source, i forgot that when the dialog was created it was immediately hidden and the thread was suspended.
now, if the open dialog was still visible (i guess there is some piece of code rejecting the hide order) the thread routine responsible for opengl management was actually suspended hence no scene display. i've removed the problematic lines and all is fine now
|
|
|
|
|
Hello,
I have an App. based on a CFormView, when I size my App. and than open a random file, the app. is sized back to its initial size. Any ideas to keep it from sizing back? This behaviour seems to be by design because I created a new project with the Classwizzard and didn't add any code and it still sizes back to its initial state!
Thanks,
Arjan.
|
|
|
|
|
I'm working on a logon-replacement for Win2k and WinXP (a new GINA).
From the logon-dialog I have to play a sound (prompt the user to log on), but PlaySound fails. LastError is "the operation completed sucessfully".
Is there any other way to play sound?
The funny thing is, if I log on and then log off again, PlaySound works fine. It's like the sound drivers don't get started before I log on.
I have the same problem with recording sounds, but I havent looked enough at this to say what functions that fails, but it looks like I have no soundcard...
[edit]When recording waveInOpen fails...[\edit]
- Anders
Money talks, but all mine ever says is "Goodbye!"
|
|
|
|
|
hi i have a problem
in my project i have to take a Object of a class(Master object). and then define another object of that class (Temporary object) that holds the same contents as the master object. if i change contents of this Temporary object the master object should take no changes.
for example if i define these 2 objects as pointer (node * master; node * temp;) and then i equalize these 2 object (master=temp;) if i change temp , Master object will be changed also.
i think this is becouse of Structure of the pointers.so is there any way to define another object of this class that get the Master Contents and even i change temp contetnts the master object take no changes.
in visual C++ ver6.0 i can define this : node * master=new node; node tmp=*master;
but in visual C++ .Net even use this structure an Error Occures : Cannot convert from node to node
how can i fix this ?
thnkx and sorry for my bad english
class node{
public:
int k;
ink l;
};
void main(){
node *master;
node *tmp;
tmp=master;
tmp->k=10;
node a;
node b;
a=b;
}
|
|
|
|
|
Hi, you need to clone the object so that master and tmp point to different things. This can be done like this:
...
node * tmp=new node(*master);
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
COOL . this is a Great function and works in Visual C++ 6 also. but it seems that the structure of Clone object in Visul C++.Net has been changed. do u know the same code in this version Plzzzz ???
thanksss
|
|
|
|
|
What Clone object? Don't mean to be rude, but I think you're lacking the basic notions of how to program in C/C++. If you have the time I strongly recommend you buy/download some tutorial on C++ programming to guide you in your venturing into C++ land.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
thanks anyway. i am studing C++ for 2 years and i know all of the properties of pointers. but i am using Visual C++.Net MFC imvironment and it seem that the definition of class and some other sructures are changed.
when i use node * tmp=new node(*master) simply i called copy constructors of master object. plz can u tell me the code in .Net ? i realy need it.
|
|
|
|