Re: PIKE_MODULE_INIT/EXIT in a normal pgsql.pike file

Henrik Grubbström <[email protected]>
Newsgroups gmane.comp.lang.pike.user
Organization Roxen Internet Software AB
Message-ID <[email protected]>
On Wed, 22 Oct 2014, Stephen R. van den Berg wrote:

> Stephen R. van den Berg wrote:
>> However, in order to get this flying I basically need to run
>> a separate pgsql backend.  Currently I simply start up a new one in a separate
>> thread for every connection to the database.
>> But, these could be shared by all pgsql connections.
>
>> So, is there some kind of PIKE_MODULE_INIT/EXIT or C-static equivalent
>> which I could use to make sure that I only create at most one thread
>> for this?
>
> Despite the overwhelming response to this question, I tried to investigate
> on my own, and basically I came up with (drumroll):

The equivalent of PIKE_MODULE_INIT for a pmod is create() (or __INIT()),
and destroy() for PIKE_MODULE_EXIT (though there are no guarantees that 
either will be called on exit).

> It's ugly, but it seems to be the only way to have some kind of global
> state over which different threads can meet and sync up.
> However, I'd need a way to serialise a reference to an object (a shared
> backend, to be precise).

Is there a reason a variable in a pmod wouldn't suffice?

-- 
Henrik Grubbström					[email protected]
Roxen Internet Software AB
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.