Thread View: comp.os.os2.programmer.misc
2 messages
2 total messages
Started by Carsten Whimster
Thu, 19 Oct 1995 14:36
Q: How do DLLs and threads work in OS/2? (VX-REXX)
Author: Carsten Whimster
Date: Thu, 19 Oct 1995 14:36
Date: Thu, 19 Oct 1995 14:36
36 lines
2340 bytes
2340 bytes
I have a DLL which has a static structure with a char string and an
integer, and I have a VX-REXX front-end which is calling this. Every
time a copy of the VX-REXX app starts up, it calls an init function in
the DLL, which sets the integer (count) to 0. Then each time it calls
another function in the DLL (ppGetParm()), it gets back the number of
times ppGetParm has been called. This function is called by a button,
which displays the number on the face of itself.
All of this works fine.
Then I started up a copy of the VX-REXX app, pressed the button (which
gets the count and displays it on the button face) a few times. Then I
started up another copy of the VX-REXX app, expecting the init it
calls to zero the count. The strange thing is that I was only doing
this to verify that threads don't work well with static variables in a
DLL, but as it turned out, it worked! That is, the first app kept its
own count correctly when the button was pressed, but the new version
of the app started at 0, and then counted correctly too!
What gives? I was just warned that static variables in a DLL aren't
thread-safe, but maybe I am misunderstanding something here. It seems
to work the way I wanted it to, without any changes, whereas I was
expecitng to have to write some kind of initialization routine for
each instantiation of an app using the DLL.
What should I do? Just write and use it the way it is, or rewrite it
in some other way, without static variables? In the second case, what
is the methodology I should use, ie. what basic algorithm works here?
Does this have something to do with the contents of the lnk file?
--
Carsten Whimster bcrwhims@uwaterloo.ca
EDM/2 Associate Editor and Book reviewer
Team OS/2 POV-Panel/2 author
http://www.undergrad.math.uwaterloo.ca/~bcrwhims/
Re: Q: How do DLLs and threads work in OS/2? (VX-REXX)
Author: Andy Stritof
Date: Thu, 19 Oct 1995 20:22
Date: Thu, 19 Oct 1995 20:22
40 lines
2593 bytes
2593 bytes
Carsten Whimster (bcrwhims@undergrad.math.uwaterloo.ca) wrote: [snip - description of setup and test] : What gives? I was just warned that static variables in a DLL aren't : thread-safe, but maybe I am misunderstanding something here. It seems : to work the way I wanted it to, without any changes, whereas I was : expecitng to have to write some kind of initialization routine for : each instantiation of an app using the DLL. You have two processes running here and the default for links on DLLs is for each process to have its own memory area (a DATA NONSHARED line in the .def file) - you can change that and then you should see the behavior you were expecting. As to static variables not being thread safe, I don't know. Threads share global data areas within a process and if its important to keep the threads from trouncing each other, you can serialize access to data with semaphores or other methods (saw an example once where threads were controlled with message Qs instead of semaphores). : What should I do? Just write and use it the way it is, or rewrite it : in some other way, without static variables? In the second case, what : is the methodology I should use, ie. what basic algorithm works here? In the scenario you described, nothing. If you wish to have each process access the same data, consider using a shared memory area outside the dll (that would prevent a second init from wiping out the count) or share the data area of the dll (I'd use shared mem most of the time - all depends on the situation) : Does this have something to do with the contents of the lnk file? The def. Cheers! -- *-------------------------*---------------------------------------------* * Andy Stritof | Transport of implements of husbandry wider * * stritof@xnet.com | than 8 ft. 6 in. beyond this point is * * | strictly prohibited. * *-------------------------*---------------------------------------------*
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads