state-threads
[Top] [All Lists]

per-thread global variables

To: state-threads@xxxxxxxxxxx
Subject: per-thread global variables
From: Matthijs Sypkens Smit <matthijs@xxxxxxxxxxxxx>
Date: Tue, 26 Sep 2000 00:08:01 +0200
Sender: owner-state-threads@xxxxxxxxxxx
Hi all,

I'm currently working on a project to create a client-server implementation 
of a differential equation analysis tool. It is supposed to be a combination 
of a Java applet for defining, showing en editing systems and a deamon for 
providing methods of integration and computing-power.

Since it must be able to handle more connections (by different users) 
simultaneously, I thought the state thread lib would be very useful for this. 
I took the server-example and played with it a little, which brought me to 
the following question:

What is the best way to handle data that is needed by many functions, but is 
different on a connection basis?

I'll expand on that. As long as the user is logged in on the server with the 
applet, there's an open connection which provides for a permanent/continous 
means of communcation. Once the connection is established many variables have 
to kept track of, for instance the definitions of multiple systems of 
differential equations and their solutions. Every user can input his own 
systems so every thread that handles a connection has a different set of data 
(which is different in size as well).

A great deal of this data needs to be accessed by many routines. To me it 
looks therefor logical to have this data global to every controling thread, 
but not to the others.

What are my options? I don't think it's possible to just define globals in my 
redefinition of handle_connection() (in a seperate c-file), because --if I 
understand things correctly-- this data would be the same for every thread. I 
saw in the documentation a section "Per-Thread Private Data" with four 
routines probably exactly for this issue. Is this what I need or are there 
other options? Is using these methods practical even for large amount of data 
(variables)? (and how does that actually work? I'm not sure I understand...)

The last option I can conceive of is passing all the necessary variables to 
the routines that need them. Might it be a sign of bad design if this seems 
to over-complicate the code with many function-parameters? At this time it's 
hard to say how many variables actually need to be passed to how many 
funtions and what the level of (im)practicality is, because this still needs 
to be evaluated. I'm not sure yet how big a problem this might pose.

This might be more of a issue of the C language than of the state-thread 
library, but considering that there're some people around here with 
experience in this field I took my chances.

I know that it might be hard to say something about this, considering you 
don't have a detailed idea of how things are supposed to work and so on, but 
any insights and/or comments are appreciated,

TIA,


-- 
Matthijs
** Do you know EVERYthing there is to know about your idol? **
Check it out:  http://www.fanpagesindex.com/

<Prev in Thread] Current Thread [Next in Thread>