Hi,
I've been working on a DLL for some time now and - as a beginner - not realized the consequences of programming for multi-user applications.
As soon as I link my dll to an ASP page using a COM (apartment threaded), I'm running into problems (i.e. crash of the web server).
I've read Rector & Newcomer on synchronization, so I skipped all the globals from my DLL and put them into a type which I pass around from one function to another. I only use one global array to store a value that I use for statement numbers. The function that handles all changes and reading is starting with a critical section.
It still didn't work. I've left out the threading that I use within my dll, no change.
I've tried to copy the DLL (trick I found on this BBS), no real change.
Now I've found this : http://www.unet.univie.ac.at/aix/aix..._safe_code.htm
Basically, they tell in a simple matters what you should and shouldn't do (finally found one!).
Anyway, just some questions about this (assuming the 'rules' for 'perfect' re-entrance):
1) It is said that it's better to change the interface to have different incoming and outgoing variables.
Am I correct if this goes as far as : as soon as a var changes in a function, I should store the values in a differnt variable?
2) What about a Type then? Is it applying to the Type as a whole or just a member? To put it differently : When Type1 is passed to a function that changes member1, can I store it in member2 or should I store it in a differnt Type alltogetter.
3) The use of local vars is - if I'm not mistaken - not really recommended if you want to have a perfect re-entrance situation. The initialization of the local is blocking the next thread.
How much is this affecting the performance? Is it really that bad?
How do you do this then? I can see it for one function but you have to initialise the variables somewhere! Is there a 'best practice' in this regard?
Hope someone can help.
Sincerely
Jeroen Brouwers
------------------
I've been working on a DLL for some time now and - as a beginner - not realized the consequences of programming for multi-user applications.
As soon as I link my dll to an ASP page using a COM (apartment threaded), I'm running into problems (i.e. crash of the web server).
I've read Rector & Newcomer on synchronization, so I skipped all the globals from my DLL and put them into a type which I pass around from one function to another. I only use one global array to store a value that I use for statement numbers. The function that handles all changes and reading is starting with a critical section.
It still didn't work. I've left out the threading that I use within my dll, no change.
I've tried to copy the DLL (trick I found on this BBS), no real change.
Now I've found this : http://www.unet.univie.ac.at/aix/aix..._safe_code.htm
Basically, they tell in a simple matters what you should and shouldn't do (finally found one!).
Anyway, just some questions about this (assuming the 'rules' for 'perfect' re-entrance):
1) It is said that it's better to change the interface to have different incoming and outgoing variables.
Am I correct if this goes as far as : as soon as a var changes in a function, I should store the values in a differnt variable?
2) What about a Type then? Is it applying to the Type as a whole or just a member? To put it differently : When Type1 is passed to a function that changes member1, can I store it in member2 or should I store it in a differnt Type alltogetter.
3) The use of local vars is - if I'm not mistaken - not really recommended if you want to have a perfect re-entrance situation. The initialization of the local is blocking the next thread.
How much is this affecting the performance? Is it really that bad?
How do you do this then? I can see it for one function but you have to initialise the variables somewhere! Is there a 'best practice' in this regard?
Hope someone can help.
Sincerely
Jeroen Brouwers
------------------
Comment