2001-07-30 21:09:47

by isnkrnl

[permalink] [raw]
Subject: Bizarre multithread open/close problem

I'm not sure if this is a bug or not but my
coworker has a wierd one.

He has 2 threads, main and helper.

main:
f=open(/dev/brcmrec) does some work and then

spawns helper:

helper spins forever doing various ioctls, read
and writes on f which was opened in main. Every
time through it looks at a "amIDone" flag which is
set by main. pthreads are the threads.

Then at some point main wants to end helper and
close f. Main sets "amIDone" which tells helper
to terminate and then successfully closes f.

Now here is the problem, our brcmrec driver has a
close() function which isn't getting called when
main does the close, at least not all of the
time.
We're beginning to think that if the helper thread
is in the middle of an ioctl or something then the
close works but it doesn't call the close on the
driver.


I don't even know what kind of help to ask for
here, so feel free to poke at this any ways you
like. I guess the bothersome part is that we have
a thread that doesn an open (did I mention it was
an exclusive open?) and then spawns a thread and
then does a close and we can't reopen the device
and the close part of our driver is never called.

Any ideas or hints?

thanks,
Ian Nelson


2001-07-30 22:46:27

by Ignacio Vazquez-Abrams

[permalink] [raw]
Subject: Re: Bizarre multithread open/close problem

On Mon, 30 Jul 2001 [email protected] wrote:

> I'm not sure if this is a bug or not but my
> coworker has a wierd one.
>
> He has 2 threads, main and helper.
>
> main:
> f=open(/dev/brcmrec) does some work and then
>
> spawns helper:
>
> helper spins forever doing various ioctls, read
> and writes on f which was opened in main. Every
> time through it looks at a "amIDone" flag which is
> set by main. pthreads are the threads.
>
> Then at some point main wants to end helper and
> close f. Main sets "amIDone" which tells helper
> to terminate and then successfully closes f.
>
> Now here is the problem, our brcmrec driver has a
> close() function which isn't getting called when
> main does the close, at least not all of the
> time.
> We're beginning to think that if the helper thread
> is in the middle of an ioctl or something then the
> close works but it doesn't call the close on the
> driver.
>
>
> I don't even know what kind of help to ask for
> here, so feel free to poke at this any ways you
> like. I guess the bothersome part is that we have
> a thread that doesn an open (did I mention it was
> an exclusive open?) and then spawns a thread and
> then does a close and we can't reopen the device
> and the close part of our driver is never called.
>
> Any ideas or hints?
>
> thanks,
> Ian Nelson

What if you use a semaphore to prevent the parent from close()ing it until the
child is done?

--
Ignacio Vazquez-Abrams <[email protected]>