[vlc-devel] [PATCH 1/6] os2: implement vlc_once()

Rémi Denis-Courmont remi at remlab.net
Tue Apr 3 11:29:34 CEST 2018


Le mardi 3 avril 2018, 12:22:12 EEST KO Myung-Hun a écrit :
> Rémi Denis-Courmont wrote:
> > Le lundi 2 avril 2018, 12:28:59 EEST Kamil Rytarowski a écrit :
> >> On 02.04.2018 08:58, Rémi Denis-Courmont wrote:
> >>> Le lundi 2 avril 2018, 03:20:25 EEST Kamil Rytarowski a écrit :
> >>>> Just follow an existing approach like in NetBSD:
> >>>>      53 int
> >>>>      54 pthread_once(pthread_once_t *once_control, void
> >>>>      (*routine)(void))
> >>>>      55 {
> >>>>      56 	if (__predict_false(__uselibcstub))
> >>>>      57 		return __libc_thr_once_stub(once_control, routine);
> >>>>      58
> >>>>      59 	if (once_control->pto_done == 0) {
> >>>>      60 		pthread_mutex_lock(&once_control->pto_mutex);
> >>>>      61 		pthread_cleanup_push(&once_cleanup, &once_control-
> >> 
> >> pto_mutex);
> >> 
> >>>>      62 		if (once_control->pto_done == 0) {
> >>>>      63 			routine();
> >>>>      64 			once_control->pto_done = 1;
> >>>>      65 		}
> >>>>      66 		pthread_cleanup_pop(1);
> >>>>      67 	}
> >>>>      68
> >>>>      69 	return 0;
> >>>>      70 }
> >>>> 
> >>>> https://nxr.netbsd.org/xref/src/lib/libpthread/pthread_once.c#54
> >>> 
> >>> This violates the memory model just like the first proposal.
> >> 
> >> Please elaborate.
> > 
> > pto_done is accessed outside the memory model.
> 
> Do you mean that pto_done should be in the block protected by mutex ?

No. I only mean that pto_done is accessed outside the definitions of the 
memory model. Nothing more, nothing less.

Mutex protection might solve that specific problem depending how it's done. 
But that's not necessarily the best way to address the real problem - 
implementing vlc_once().

-- 
Rémi Denis-Courmont


More information about the vlc-devel mailing list