Re: gthread once
- From: Miroslaw Dobrzanski-Neumann <mne mosaic-ag com>
- To: GTKDEV <gtk-devel-list gnome org>
- Subject: Re: gthread once
- Date: Tue, 19 Feb 2002 10:37:42 +0100
On Tue, Feb 19, 2002 at 10:08:33AM +0100, Sebastian Wilhelmi wrote:
> Hi Miroslaw,
>
> > To the bug 69688 I have attached (attachment id 6767) a patch with fast
> > implementation of g_thread_once(). I is implementad in terms of already
> > present gthread abstraction. I does not block the whole system while running
> > the once handler but only all threads waiting on the particular once guard.
> >
> > the test case thread-test has been extended to run the once test also.
> >
> > Could you review the fix and apply if appropriate?
>
> Firstly as a matter of fact this of course won't make it for 2.0.
>
> Now to the implementation:
>
> * It is not guaranteed to work. (We have this discussion every
> half year, and I think, I'm the top offender;-) Basically the
> double check pattern is not safe for some (admittedly not so
> common) systems. We could use this technique, where it is
> allowed, and fall back to full locking on the other platforms.
for such systems you can redefine the macro g_thread_once() to direct call to
g_thread_once_real()
it could be estimated by configure
> * I think, we should support calling a function, which takes an
> argument (gpointer) and returns a gpointer to make this more
> useful. Such an implementation could be used to implement
> g_static_mutex_get_mutex_impl, which is my aim in including
> g_once. Your implementation couldn't do that. Actually the
> pthread implementation is of very limited use due to that. [I
> didn't wrote that in the bug report, because i first thought
> of it after submitting the report.]
once function taking a parameter is no more invariant as it should be. Its
outcome depends on the parameter passed. The initialization result can be
stored in a global variable since it does not change after initialization has
taken place.
here a broken once issue (pseudocode)
noone can tell how this code behave!!
once_type myonce = ONCE_INIT;
void ini_func(void *p)
{
if (p)
abort();
}
void *thread1(void*)
{
sleep (random());
thread_once(&myonce, &ini_func, NULL)
}
void *thread1(void*)
{
sleep (random());
thread_once(&myonce, &ini_func, (void*)0x1)
}
int main(void)
{
t1 = start_thread(&thread1);
t2 = start_thread(&thread2);
join(t1);
join(t2);
return 0;
}
--
Miroslaw Dobrzanski-Neumann
MOSAIC SOFTWARE AG
Base Development and Research
Tel +49-2225-882-291
Fax +49-2225-882-201
E-mail: mne mosaic-ag com
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]