[Klone-users] Global variable
Stefano Barbato
barbato at koanlogic.com
Tue Mar 18 05:23:52 EDT 2008
On 18/mar/08, at 08:49, Trung, Tran Minh wrote:
> Hi,
> I have problem again with KLone !?
> I hava a klapp to demo using global variable. My klapp has some file:
> + data.h: declare a STRUCT global variable with name “data_struct”
> + data.c: has some functions: read_data, update_data from a file
> +interface: has some .kl1 pages
> page1.kl1: when page loads, read data from file to data
> struct and display some fields of it. And after modifying some
> fields, click update button to update to data struct (on memory) and
> update to db file.
> page2.kl1: have functions like page1.kl1 but display
> some other fields of data struct.
> …
> I check all functions running well. But after updating (it is OK),
> when I go to another page and return the previous page, the data
> will display incorrectly (I check the db file, it is OK and read
> function is OK). And I go to another page and return it again, it is
> OK. Sometimes it is OK, sometimes it is wrong (it displays data I
> can not know where it is). Ohh…, what is my problem!? I think
> because I use global variables !?
>
> Thanks,
>
> Tran Minh Trung
Hi Trung,
for performance and concurrency KLone (just like most unix daemons)
forks 3 or more processes that handle incoming client requests; every
request gets served by a random "kloned" process.
Global variables live in processes private address space so every
"kloned" have its own indipendent global variables i.e. those
variables are not shared between KLone processes.
You can use session objects ( http://www.koanlogic.com/klone/api/html/group__session.html
) to keep data between multiple requests, any form of IPC (Inter
Process Communication) to share data between server processes or a
shared database like SQLite (http://www.sqlite.org).
bye,
s
More information about the klone-users
mailing list