473,574 Members | 3,134 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem with memory when using "threads" with Perl 5.8 on Windows System

I am working on a multi-threaded server for a Windows 2000 system and since
"fork" doesn't work that great in a Win32 environment, I am trying to use
use the "threads" module instead.

When a thread is complete, the handle and thread are removed but the memory
used when the thread was initially created does not appear to be released.
Any new threads created afterward will grab new memory on top of where the
previous left off.

This is a problem because what I am trying to do is create a new thread with
each new client connection, and then remove the thread when the client
disconnects. Clearly, I will run out of memory after several client
connections if it doesn't release.

Any one have a suggestion?

############### ############### ############### ########

use IO::Socket ;
use threads ;
use strict ;
sub AcceptClient {

print "Starting new thread for new client...\n" ;

my $buf ;
my $handle = shift ;
while ( defined ( $buf = <$handle>)) {
chomp $buf ;
print "Received <$buf>\n" ;

# interpret $buf as client commands and process them here...
# ...
}

print "Closing new socket\n" ;
shutdown ( $handle , 2 ) ;
undef $handle ;

print "New thread is done...\n\n" ;

return 1 ;
}

my $main_sock = IO::Socket::INE T->new( LocalPort => 9501 , Listen => 5,
Reuse => 1 , Proto => 'tcp' );
die "Socket could not be created. Reason: $^E \n" unless ( $main_sock ) ;

print "Listening for new connections...\ n" ;
my $new_sock ;

while ( $new_sock = $main_sock->accept() ) {
print "New connection accepted...\n" ;

my $thread = threads->create( \&AcceptClien t , $new_sock ) ;

$thread->detach ;

}

shutdown($main_ sock,2) ;
Jul 19 '05 #1
0 3479

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
6227
by: Michael Schutte | last post by:
I know, questions about Tkinter and threads have been answered very often, but I want to ask anyway. I am using Python 2.2 on a Linux (SuSE Linux 8.1) system. I want to write a server application; like telnet is a client. The user should be able to bind() to a port and wait for a client. The written and recieved data is stored in a Text...
10
4934
by: Drakier Dominaeus | last post by:
This is my first time posting here, so please forgive me if I do anything incorrectly. I've been learning C# and working with different things and decided I wanted to get into Multi-Threading. My problem is that I must not be doing it right because only some of the stuff works as would be expected. I'll post what exactly is happening, then...
10
3370
by: jaire | last post by:
In my application I have two threads. Each of them creates a new propertygrid. In the property grid I have a property with a color editor. Whenever i am clicking on the combo box to change the 'Color' in the first thread is fine. Any other thread that tries to modify the color in the property grid throws: "Controls created on one thread...
0
1542
by: sam | last post by:
Hi, Im using windows froms exe application to read and send messages to private message queues. Using threads how can I keep reading all the messages from MS private message queuing without lossing any message thread. Its seem to me that some messages stays in the private message queue and want pickup by " MessageQueue.Receive()". I have...
4
2515
by: David Travis | last post by:
Hello, I am working on a web application, where I should generate at some scenarios large amounts of emails. I noticed that the mailing process is pretty slow, hence the page loading when these emails are generated is slow too. If I will use threads to execute the mailing process the page will load quickly, and the thread will run in the...
4
1247
by: James A Taber | last post by:
Does someone know how to "re-cycle" threads... Thanx in advance -James A Taber
1
1589
by: IT | last post by:
I want to fire off threads to start retrieving File from several locations. FTP and the local network. Is it ok to start these threads on the main form load. Ex. Every day we load EDI files into a SQL server. When the main form start out can I have a thread run this process and disable the menu item so that the user does not try to load...
94
30250
by: Samuel R. Neff | last post by:
When is it appropriate to use "volatile" keyword? The docs simply state: " The volatile modifier is usually used for a field that is accessed by multiple threads without using the lock Statement (C# Reference) statement to serialize access. " But when is it better to use "volatile" instead of "lock" ?
4
1693
by: npankajk | last post by:
Hi, My requirement is to create 75000 files. I have a perl script to create files , it is working fine for small number of files but the script is exiting while creating large number of files. For this I used threads. The following is the script I used. Please help me where the script is failing. I have been fighting with this since...
0
7764
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8110
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8273
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
5658
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5336
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3775
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3794
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2277
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1102
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.