[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

RE: Newbie question on mutexes



Brain fart correction (thanks to Alexander)

> From: Perez-Gonzalez, Inaky
> ...
> void some_function()
> {
> 	int data = 0;
> 	mutex_t mutex = MUTEX_INITIALIZER;
> 	struct kk kk1 = { .data = &data, .mutex = &mutex, .private = private1 };
> 	struct kk kk2 = { .data = &data, .mutex = &mutex, .private = private2 };
> 	thread_descr_t thread_1_descr, thread_2_descr;
> 	spawn_thread (thread_1_descr, thread_fn, &kk1);
> 	spawn_thread (thread_2_descr, thread_fn, &kk2);
> 	join (thread_1_descr);
> 	join (thread_2_descr);}
> 	return data;
> };
> 
> Now, notice that we don't explicitly call mutex_destroy() anywhere,
> because POSIX doesn't require it. I (myself) would do it, but it
> doesn't say anywhere that it has to be done, and in fact, many
> programs are written like that.
> ...

"I (myself) would" should read "I (myself) would not", and more important:
MUTEX_INITIALIZER is valid only for statics. I don't know why I was so
sold into this, maybe because I have read too much (obviously incorrect)
code that uses it and I was stupid enough not to check against the letter
of POSIX. My fault, with no more excuses.

This kind of renders my argument moot in the strict need of automatic
disposal--I still think is needed, to simplify the caching, but maybe there
are (once again) cracks in my argumentation.

Iñaky Pérez-González -- Not speaking for Intel -- all opinions are my own (and my fault)




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]