Re: gthread once



Hi, Sebastian

On Tue, Feb 19, 2002 at 11:08:56AM +0100, Sebastian Wilhelmi wrote:
> > here a broken once issue (pseudocode)
> > noone can tell how this code behave!!
> 
> The same is true, when you use 2 different functions with one GOnce var,
> so where is the point? Of course this can be misused, but I can see
> possible uses of this, e.g. you can annotate GOnce created data with the
> specific function, which triggered the creation and so forth.

What about the followin solution:
let GOnce contain all information needed.

GOnce contains all values needed as

struct GThreadOnce
{
	sig_atomic_t once;
	GThreadOnceFunction init_func;
	gpointer param;
	gpointer retval;
}

g_thread_once* () takes only one parameter, the once control block and returns
the result of evaluation

#define g_thread_once(o) (2 != (o).once) ? g_thread_once_real(&(o)), (o).retval : (o).retval 

G_THREAD_ONCE_INIT takes two parameter: the once function and parameter to be
passed

#define G_THREAD_ONCE_INIT(f, p) {0, f, p, NULL}

Regards
-- 
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]