libthr shared locks
Konstantin Belousov
kostikbel at gmail.com
Mon Feb 15 17:56:28 UTC 2016
On Mon, Feb 15, 2016 at 05:35:33PM +0000, Martin Simmons wrote:
> >>>>> On Mon, 15 Feb 2016 16:44:10 +0200, Konstantin Belousov said:
> >
> > On Mon, Feb 15, 2016 at 02:17:20PM +0000, Martin Simmons wrote:
> > >
> > > Also, a general question: why not use some flag in the barrier (and other
> > > objects) to indicate pshared, removing the need for __thr_pshared_offpage
> > > except in init?
> >
> > But where would I keep the object ? All that I have with the current
> > ABI is a single pointer, which de facto behaves like the flag which you
> > proposed. It is either real pointer or (if set to some specific value
> > impossible for a valid pointer) there is an offpage.
>
> I'm probably missing something, but I was thinking pthread_barrier_init would
> do something like
>
> if ( attr is PTHREAD_PROCESS_PRIVATE ) {
> bar = calloc(1, sizeof(struct pthread_barrier));
> pshared = 0;
> } else {
> bar = __thr_pshared_offpage(barrier, 1);
> pshared = 1;
> }
> bar->psharedflag = pshared;
> *barrier = bar;
>
> Then pthread_barrier_destroy would use the psharedflag slot to decide how to
> free it and pthread_barrier_wait would need no changes.
A process which has the page where the initialized pthread_barrier_t is
located, must be able to operate on the barrier. Now, look at your scheme.
One process which executed pthread_barrier_init(), performed what you
proposed. What should do the pthread_barrier_wait() call in another
process, which shares the 'barrier' with the first process, but does
not share the whole address space ? After your pthread_barrier_init()
executed, barrier contains the address of the object (off-page) in the
other address space, for that process.
More information about the freebsd-arch
mailing list