Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 27 Nov 1999 19:29:45 -0800 (PST)
From:      FengYue <fengyue@bluerose.windmoon.nu>
To:        hackers@FreeBSD.ORG
Subject:   Re: PThreads and Sockets
Message-ID:  <Pine.BSF.4.10.9911271917410.42608-100000@bluerose.windmoon.nu>
In-Reply-To: <Pine.BSF.4.20.9911271746010.6921-100000@deadpixi.pernet.net>

next in thread | previous in thread | raw e-mail | index | archive | help

On Sat, 27 Nov 1999, Rob King wrote:

> 
> How would you recommend I do it? Please remember, I have no experience
> with pthreads, and any advice you give would be greatly appreciated.

There are couple of ways you could do this:

1) pass sd2's value instead of its memory address to serverstart()
 	pthread_create(&thread1, pthread_attr_default,serverstart, sd2);
   then inside serverstart:
	void serverstart (void *p)
	{
		int sockfd = (int) p;
		....blah...blah
	}

	if you worry about void * being not as the same size as int on
	some platforms, then u should use 2)

2) Use a mutex lock:
	pthread_mutex_lock (&mp_lock);
	_do_the_accept_
	_create_thread_
	inside serverstart(), right after u def' the pointer, do this
	pthread_mutex_unlock (&mp_lock);

> 
> I tried doing a pool of threads created at startup, and I think that may
> be a better approach...That would allow tighter control of resource limits
> - do something like Apache, have a "maximum number" of processes running.

Yes, that's a better approach in many cases.  Creating threads itself
is a quiet expensive operation.



To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSF.4.10.9911271917410.42608-100000>