Re: [gtk-list] Re: gdk_threads_enter is not reentrant
- From: Noel Burton-Krahn <noel burton-krahn com>
- To: gtk-list redhat com
- CC: gtk-list redhat com, gtk-list redhat com, recipient list not shown: ;
- Subject: Re: [gtk-list] Re: gdk_threads_enter is not reentrant
- Date: 13 Mar 2000 17:30:40 -0000
Sometimes you really do need to explicitly release a mutex no matter
what lock depth you're at. To do so requires you know exactly how
many time gdk_threads_lock has been called. Please at least put in a
gdk_threads_depth counter so users can do their own lock release.
Multithreaded programs really need to be able to do this, and it's
trivial to do, no matter what threads implementation you use.
/* this is only valid after gdk_threads_enter() */
int gdk_threads_depth = 0;
int
gdk_threads_enter() {
pthread_mutex_lock(gdk_lock);
return ++gdk_threads_depth;
}
void
gdk_threads_leave() {
gdk_threads_depth--;
pthread_mutex_unlock(gdk_lock);
}
int
gdk_threads_leave_depth() {
int i, depth;
i = depth = gdk_threads_depth;
while( i-- > 0 ) {
gdk_threads_leave();
}
return depth;
}
int
gdk_threads_enter_depth(int depth) {
while( depth-- > 0 ) {
gdk_threads_enter();
}
return gdk_threads_depth;
}
--Noel
> Date: Mon, 13 Mar 2000 08:53:36 +0000
> From: Sebastian Wilhelmi <wilhelmi@ira.uka.de>
>
> Hi Noel,
>
> > Thanks Sebastian, I look forward to your changes. One thing I should
> > mention: when you make gdk_threads_enter() reentrant, you should add
> > functions to release all locks no matter what depth you're at.
> > Consider this code:
>
> No, I don't think, you'll get that. As I'm going to use the native recursive
> implementation where available (Linux for example, but also Solaris 2.7; with
> a horrible broken implementation though, I wonder, how they managed to get
> that wrong), this is not possible.
>
> Bye,
> Sebastian
>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]