2008/6/11 Jerry D. Hedden <[EMAIL PROTECTED]>:
> On Wed, Jun 11, 2008 at 9:26 AM, Javier Terceiro <[EMAIL PROTECTED]> wrote:
>> Hello list,
>>
>> I am designed a new software. I am using threads. The operation is
>> correct, but memory consumption is excessive. The system is using 100
>> MB and when the software is working, 500 Mb. The memory is not
>> released, why?
>
> You need to either join the threads after they're done working, or
> else detach them.  See below.
>
>>
>> The source code is:
>>
>> -----------------------------------------------------------------------------
>>
>> #!/usr/bin/perl -w
>>
>> use strict;
>> use warnings;
>> use AnyData;
>> use Sys::Syslog;
>> use Sys::Syslog qw(:DEFAULT setlogsock);
>> use Sys::Syslog qw(:standard :macros);
>> use POSIX qw(setsid);
>> use threads;
>> use threads::shared;
>>
>> sub mail
>> {
>>        print ("The mail thread\n");
>>        return 0;
>> }
>>
>> sub mf
>> {
>>        print ("The mf thread\n");
>>        return 0;
>> }
>>
>> sub scan_files
>> {
>>        while(1)
>>        {
>>                foreach (readdir(DIRHANDLE))
>>                {
>>                        if (!-d $_)
>>                        {
>>                                my $opt =
>> choose_file_option("workq/",$_,"Delivered");
>>                                switch ($opt)
>>                                {
>>                                        case "mail"
>>                                        {
>>                                                threads->new(\&mail, $_);
>
> threads->new(\&main, $_)->detach();
>
>>                                        }
>>                                        case "mf"
>>                                        {
>>                                                threads->new(\&mf, $_);
>
> threads->new(\&mf, $_)->detach();
>
>>                                        }
>>                                        else
>>                                        {
>>                                                syslog ('daemon|info',
>> "Send mail. Failure detected");
>>                                        }
>>                                }
>>                        }
>>                }
>>                sleep(60);
>>        }
>> }
>>
>> sub daemon
>> {
>>        chdir "/";
>>        open STDIN, '/dev/null';
>>        open STDOUT, '>/dev/null';
>>        open STDERR, '>/dev/null';
>>        fork && exit;
>>        setsid();
>>        if (open PID, '>', '/var/run/program.pid')
>>        {
>>                print PID "$$\n";
>>                close PID;
>>        }
>> }
>>
>> setlogmask( LOG_MASK($Fax::Config::param{'log_info'}) );
>> openlog 'faxqr', 'pid', LOG_DAEMON;
>> daemon();
>>
>> $SIG{"TERM"} = \&notify_exit;
>>
>> scan_files();
>>
>> -----------------------------------------------------------------------------
>>
>> Any idea that there is a very high consumption of memory.
>>
>> --
>> A greeting,
>>
>> Javier.
>>
>

Hi,

I aply this changes, but now I obtein a fatal error:

*** glibc detected *** double free or corruption (!prev): 0x08fea490 ***

And the process is cancel :(

Any idea?

-- 
A greeting,

Javier.

Reply via email to