threads/74180: KSE problem. Applications those riched maximum possible threads at a time, would hang on threads join. look at detailed description !

Pavel Kraynyukhov acs at swamp.homeunix.org
Sat Nov 20 17:10:28 PST 2004


>Number:         74180
>Category:       threads
>Synopsis:       KSE problem. Applications those riched maximum possible threads at a time, would hang on threads join. look at detailed description !
>Confidential:   no
>Severity:       non-critical
>Priority:       high
>Responsible:    freebsd-threads
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sun Nov 21 01:10:26 GMT 2004
>Closed-Date:
>Last-Modified:
>Originator:     Pavel Kraynyukhov
>Release:        5.3
>Organization:
private
>Environment:
FreeBSD ChainOfWorlds.InstantHQ.COM 5.3-RELEASE FreeBSD 5.3-RELEASE #0: Fri Nov 12 15:21:33 CET 2004 root at ChainOfWorlds.InstantHQ.COM:/usr/src/sys/i386/compile/ROMUL  i386
>Description:
      Doing some measuring tests i found that application that creates a maximum possible threads in process, and then joins those threads after condition broadcasted, impossible to run more then once per boot. On second run the test hangs on threads joining. So you must reboot a PC to successfully pass this test again.
>How-To-Repeat:
      compile following C++ test and run it twice or more times sequentually. 
first test will pass sucessfuly.
second one (and all following)  will hang on threads joining.

#include <pthread.h>
#include <time.h>
#include <vector>
#include <math.h>
#include <exception>
#include <iostream>

pthread_cond_t WakeThemUp;
pthread_mutex_t lock;

void* thread(void* args)
{
        pthread_mutex_lock(&lock);
        pthread_cond_wait(&WakeThemUp,&lock);
        pthread_mutex_unlock(&lock);
/*      for(size_t i=1; i< 1000;i++)
        {
                float m=i;
                m=log(sqrt(m*3.14/0.3876543234*234.765438/2.666666));
                m+=i;
        }*/
}

int main()
{
        std::vector<pthread_t*> threads;
        size_t thrcount=0;
        pthread_cond_init(&WakeThemUp,NULL);
        pthread_mutex_init(&lock,NULL);
        clock_t start=clock();
        clock_t end=0;

        try{
                while(1)
                {
                        pthread_t *threadP=new pthread_t;
                        if(pthread_create(threadP,NULL,thread,NULL)==0)
                        {
                           threads.push_back(threadP);
                           thrcount++;
                        }
                        else throw 1;
                }
        } catch( ... )
        {
                end=clock();
                std::cout << "threads created: " << thrcount << " ,\
		 creation time: " << end-start << " \
		 ticks" <<" CLOCKS_PER_SEC(" <<CLOCKS_PER_SEC << ")" << std::endl;
                pthread_cond_broadcast(&WakeThemUp);
 
               for(size_t i=0;i<threads.size();i++)
                {
                        pthread_join(*threads[i],NULL);
                }
                start=clock();
                std::cout << "wait and join have taken " << start-end <<" ticks\n";
        }

        return 0;
}

>Fix:
      
>Release-Note:
>Audit-Trail:
>Unformatted:


More information about the freebsd-threads mailing list