Subject | Re: [ib-support] How can I set a generator value inside a procedure? |
---|---|
Author | Frederik Nosi |
Post date | 2002-11-07T14:05:03Z |
Thank you for your reply
On Thursday 07 November 2002 12:49, Svein Erling Tysvaer wrote:
> At 12:50 07.11.2002 +0000, you wrote:
> > > > GEN_ID (GENERATOR, NEWVALUE - GEN_ID (GENERATOR,0) );
> > >
> > > Right, but this isn't safe in a multi user environment.
> >
> >Is not safe the expression ? If this is the case can you give more info?
> >And yes, I agree that setting a GEN_ID after creation does not make sense
> > IMHO
>
> Generators are outside transaction control. I would assume that the inner
> GEN_ID is called before the outer GEN_ID, but there is nothing preventing
> anyone else from calling GEN_ID between those calls.
>
> Say you call
> GEN_ID (GENERATOR, 1 - GEN_ID (GENERATOR,0) );
> you would expect the generator afterwards to be 1. Let's see what I assume
> could happen if this call is made twice simultaneously:
>
> Lets say that GENERATOR has the value of 100:
>
> First, both of them issue the inner call to GEN_ID(GENERATOR,0) - which
> returns 100 in both cases.
>
> Then, one of them sets the GENERATOR to (100, 1-100) =1 and then the other
> one sets the generator to (1,1-100) = -98
>
> An unlikely event, but theoretically possible, so it ought to be avoided.
Ok, now can I assume that a call to GEN_ID(...) without function calls in the
argument part is safe from threading issues? If so I understand that the
problem in the case of the setting of the generator lies in the time gap from
the inner call of GEN_ID() to the beggining of execution of the outer
GEN_ID(). Is this right?
>
> I know nothing about the internals of Firebird and may be wrong in my
> reasoning, but this is what I expect could happen in the worst case.
>
> Set
Fredi