RE: pthreads ??

1999-09-20 Thread Isaac Richards


On 20-Sep-99 [EMAIL PROTECTED] wrote:
> I agree with you, but it even gets worse than that. Let me elaborate.
> The signal handling under LinuxThreads is different from the signal
> handling under POSIX threads for one. And, as far as I can tell, the
> signal handling is cooperative, and the current thread implementation
> does not cooperative signal handling. The code for suspend and resume
> is show here:


Oh well, just another place where linux doesn't follow the standard..  Guess I
shouldn't believe my ora pthreads book =)

Isaac



RE: pthreads ??

1999-09-20 Thread robert

Jim Carlson sez:
>> Are calls to suspend and resume ref counted? iow, if i do this in
>> pseudo-code:
>
>No.  It just does a SIGSTOP and SIGCONT for suspend and resume.  The
>first resume after N>=1 suspends will cause the task to restart.
>
>> is that the way it works for pthreads?
>
>Pthreads doesn't really have suspend/resume.  Just SIGSTOP and
>SIGCONT.

I agree with you, but it even gets worse than that. Let me elaborate.
The signal handling under LinuxThreads is different from the signal
handling under POSIX threads for one. And, as far as I can tell, the
signal handling is cooperative, and the current thread implementation
does not cooperative signal handling. The code for suspend and resume
is show here:


void
linuxThread::
Suspend()
{
m_suspendMutex->Acquire(WAIT_FOREVER);
if (!m_suspended) {
   pthread_kill(m_threadHandle, SIGSTOP);
   m_suspended = true;
}
m_suspendMutex->Release();
}

void
linuxThread::
Resume()
{
m_suspendMutex->Acquire(WAIT_FOREVER);
if (m_suspended) {
   pthread_kill(m_threadHandle, SIGCONT);
   m_suspended = false;
}
m_suspendMutex->Release();
}  

So, I wrote this little test program, to see how well the
internals of Suspend and Resume work:

#include 
#include 
#include 
#include 
#include 

void tprint(char *string)
{
 time_t t;

 time(&t);
 printf("%s%s\n", ctime(&t), string);
}

void *worker_thread(void *pArg)
{
 tprint("Worker thread start, sleeping 5 secs\n");
 sleep(5);

 tprint("Back from sleep, worker thread exiting...\n");

 return NULL;
}

int main(int argc, char *pargv[])
{
 pthread_t t;

 t = pthread_create(&t, NULL, worker_thread, NULL);

 tprint("Main thread starting\n");
 sleep(1);

 tprint("Suspending thread...\n");
 pthread_kill(t, SIGSTOP);

 sleep(10);
 tprint("Exit...\n");

 return 0;
} 

The output of this program is:

Mon Sep 20 11:15:45 1999
Main thread starting

Mon Sep 20 11:15:45 1999
Worker thread start, sleeping 5 secs

Mon Sep 20 11:15:46 1999
Suspending thread...

Mon Sep 20 11:15:50 1999
Back from sleep, worker thread exiting...

Mon Sep 20 11:15:56 1999
Exit...  

As you can see, the worker thread never gets interrupted or slowed
down. This is exactly what would happend with the current Thread.cpp
class for linux.

Conclusion: We should not use Suspend() and Resume(). As a matter of
fact it would be best for us to remove these calls from the classes
altogether.



--ruaok Freezerburn! All else is only icing. -- Soul Coughing

Robert Kaye -- [EMAIL PROTECTED]  http://moon.eorbit.net/~robert



Re: pthreads ??

1999-09-20 Thread carlson

> Are calls to suspend and resume ref counted? iow, if i do this in
> pseudo-code:

No.  It just does a SIGSTOP and SIGCONT for suspend and resume.  The
first resume after N>=1 suspends will cause the task to restart.

> is that the way it works for pthreads?

Pthreads doesn't really have suspend/resume.  Just SIGSTOP and
SIGCONT.

-- 
James Carlson, Software Architect   <[EMAIL PROTECTED]>
IronBridge Networks / 55 Hayden Avenue   71.246W   Vox:  +1 781 372 8132
Lexington MA  02421-7996 / USA   42.423N   Fax:  +1 781 372 8090
"PPP Design and Debugging" --- http://people.ne.mediaone.net/carlson/ppp



Re: pthreads ??

1999-09-20 Thread Mark B. Elrod

that is how i think it should work... and it is how i need it to work for my
download stuff to work correctly.

elrod

Isaac Richards wrote:

> >From what I can tell, nope.  Shouldn't be more than 5 minutes work to add it,
> if that's how you want them to behave..
>
> Isaac
>
> On 20-Sep-99 Mark B. Elrod wrote:
> > Are calls to suspend and resume ref counted? iow, if i do this in
> > pseudo-code:
> >
> > thread->suspend();
> > thread->suspend();
> >
> > thread->resume();
> > // thread is still suspended
> > thread->resume();
> > // now thread runs
> >
> > is that the way it works for pthreads?
> >
> > elrod
> >
> >



RE: pthreads ??

1999-09-20 Thread Isaac Richards

>From what I can tell, nope.  Shouldn't be more than 5 minutes work to add it,
if that's how you want them to behave..

Isaac

On 20-Sep-99 Mark B. Elrod wrote:
> Are calls to suspend and resume ref counted? iow, if i do this in
> pseudo-code:
> 
> thread->suspend();
> thread->suspend();
> 
> thread->resume();
> // thread is still suspended
> thread->resume();
> // now thread runs
> 
> is that the way it works for pthreads?
> 
> elrod
> 
>