Re: condvar

"François Revol" <[email protected]>
Newsgroups gmane.os.openbeos.kernel.devel
Message-ID <43254930166-BeMail@patrick>
> Hi there,
> 
> to be able to efficiently implement a condvar mechanism (and similar 
> things), it would be great to atomically release one semaphore while 
> aquiring another.
> Together with the new B_RELEASE_ALL flag, condvar could then be 
> implemented very easily.
> 
> The functionality is very trivial to implement, that's why I've 
> already 
> done it - the question is on how we make it public.
> There are basically 3 possibilities:
> 1) keep it private for R1
> 2) (the messy version) add another flag to acquire_sem_etc() that 
> reinterpretes the "count" parameter as semaphore to be released - 
> this 
> has the advantage that no new system call is added; it's by no means 
> backwards compatible, though (the app would run incorrectly on 
> systems).

That would change the semantics of the "count" parameter and its 
name...
Btw, after checking it seems acquire_sem_etc just doesn't care about 
undefined flag values (>16) in R5. Would it return EINVAL or somethign 
we could use it, and have a slower fallback maybe...

> 3) (the clean version) add a new pair of system calls: switch_sem() 
> and 
> switch_sem_etc() (other naming suggestions are welcome). Applications 
> using these functions would not run on R5 or Zeta anymore.

Shouldn't those condvar and friends be wrapped into objects in 
libraries anyway ?
Btw, there is a big issue with the current pthread implementation as 
well as yours: it doesn't handle the STATIC initializers...
They both declare the basic pthread _t types as pointers to structs, 
for extensibility... and:
#define PTHREAD_MUTEX_INITIALIZER	NULL
#define PTHREAD_COND_INITIALIZER	NULL
#define PTHREAD_RWLOCK_INITIALIZER	NULL

But that prevents apps doing:

pthread_mutex_t m = PTHREAD_MUTEX_INITIALIZER;
and just using it, since the funcs will get a NULL, and can't use that.
(the R5 lib actually tries to acquire a pseudo-spinlock from that 
struct to lazily initialize it... except it's still NULL, so it 
crashes.

François.



-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_ide95&alloc_id396&op=click
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.