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

Re: pthreads help needed to diagnose #98866



On Mon, May 28, 2001 at 06:38:25PM -0400, Matt Zimmerman wrote:
> On Mon, May 28, 2001 at 11:09:07AM -0500, Gordon Sadler wrote:
> 
> > Ok, I see what you are expecting now. However, it is reversed here. Your
> > BROKEN causes output:
> > gbsadler 24986  0.0  0.5  1824  724 tty3     S    11:00   0:00 ./threadtest
> > gbsadler 24986  0.0  0.5  1832  756 tty3     S    11:00   0:00 ./threadtest
> > gbsadler 24991  0.0  0.5  1832  756 tty3     S    11:00   0:00 ./threadtest
> > 
> > while WORKS1 produces:
> > gbsadler 24941  0.0  0.5  1824  724 tty2     S    10:59   0:00 ./threadtest
> > gbsadler 24941  0.1  0.6 40752  844 tty2     S    10:59   0:00 ./threadtest
> > gbsadler 24946  0.0  0.6 40752  844 tty2     S    10:59   0:00 ./threadtest
> > gbsadler 24948  0.0  0.6 40752  844 tty2     S    10:59   0:00 ./threadtest
> > ...
> > with increasing PIDs for a total of 22 items. The VSZ does not change on later PIDs
> 
> It sounds like ps is being run before all of the threads have exited.  Maybe
> you should try increasing the sleep() at the end.  Are you commenting out
> #define BROKEN when you #define WORKS1?
> 
> The problem is that even after the spawned threads have exited, virtual memory
> usage remains at nearly the same level (about 40MB here also, or 2MB per
> thread).  This is what happens if you create joinable threads and never join
> with them, but should not happen with detached threads.
> 
Hmm, I still seem to get differing behavior. BROKEN and WORKS2 produce
same/similar output, WORKS1 continues above results (I increased sleep
to 10, no difference).

I have made a change to get consistent behavior. Apparently the reason
WORKS1 was differing was, it needed a global Semaphore..
I'm not positive if you need to pass the Semaphore to thread->Run(), but
it now produces the same ouput for all three defines, with no massive
increase in VSZ.

--- threadtest.cc       Mon May 28 18:56:43 2001
+++ threadtest_mine2.cc Mon May 28 18:57:45 2001
@@ -19,6 +19,10 @@
 //#define WORKS1
 //#define WORKS2
  
+#ifdef WORKS1
+    Semaphore sem;
+#endif
+
 class ThreadTest: public virtual Thread {
 public:
   ThreadTest(Semaphore *sem): Thread(sem) { };
@@ -38,6 +42,7 @@
     //
	    
     ThreadTest *thread = new ThreadTest(NULL);
+    thread->Start();
		 
 #elif defined(WORKS1)
		  
@@ -47,15 +52,14 @@
 // pthread_create() from Thread::Thread instead of Thread::Start)
 //

-    Semaphore sem;
     ThreadTest *thread = new ThreadTest(&sem);

-#endif
				 
     // For the semaphore case, this posts to the semaphore and lets
     // the thread continue.  For the non-semaphore case, this creates
     // the thread.  See code for Thread::Start below.
     thread->Start(&sem);
+#endif
   }
   sleep(5); // Allow threads to exit
   system("ps ux | grep threadtest | grep -v grep");


-- 
Gordon Sadler



Reply to: