Mailing List archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[vdr] Re: vdr-1.3.17: thread issues with vdr-xine and vdr-osdteletext



Hi,

Reinhard Nissl wrote:

C.Y.M wrote:

Reinhard Nissl wrote:
>>
C.Y.M wrote:

Attached you'll find a suggested fix. It works for me here.
It works for me too! Thank you so much. I have applied this patch to the latest thread.[ch] and streamdev works like a charm again. :)

Excellent work.
Well, there are still some issues left:
1.) what happens if StartThread() get's never called?
    Deadlock at childTidChanged.Wait().
In what situation would StartThread() not be called?
When pthread_create() fails.

2.) what happens if StartThread() returns before the Wait() is reached?
    Deadlock at childTidChanged.Wait().
Isnt that what the mutex is for?
Hmm. I thought of the case where StartThread() is very fast and locks the Mutex, changes childTid, unlocks it, executes Action(), locks the Mutex, changes childTid again and unlocks the mutex. If then Wait() is reached, there is a deadlock.

But you are right: moving up the cMutexLock before pthread_create() should solve this issue, as childTid then cannot be modified before the Wait() is reached.

So some error checking and an additional variable for indicating whether StartThread() returned already will be necessary and maybe a TimedWait(), too.
I've just modified it like that:

bool cThread::Start(void)
{
cMutexLock startLock(&startMutex);
if (!childTid) {
parentTid = pthread_self();
pthread_t Tid;
cMutexLock childTidLock(&childTidMutex);
int err = pthread_create(&Tid, NULL, (void *(*) (void *))&StartThread, (void *)this);
pthread_detach(Tid); // auto-reap
pthread_setschedparam(Tid, SCHED_RR, 0);
if (!err)
childTidChanged.Wait(childTidMutex);
}
return true; //XXX return value of pthread_create()???
}

Bye.
--
Dipl.-Inform. (FH) Reinhard Nissl
mailto:rnissl@gmx.de




Home | Main Index | Thread Index