From dev-return-12900-apmail-apr-dev-archive=apr.apache.org@apr.apache.org Tue Sep 28 07:32:32 2004
Return-Path:
Delivered-To: apmail-apr-dev-archive@www.apache.org
Received: (qmail 39775 invoked from network); 28 Sep 2004 07:32:32 -0000
Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199)
by minotaur-2.apache.org with SMTP; 28 Sep 2004 07:32:32 -0000
Received: (qmail 18861 invoked by uid 500); 28 Sep 2004 07:32:30 -0000
Delivered-To: apmail-apr-dev-archive@apr.apache.org
Received: (qmail 18826 invoked by uid 500); 28 Sep 2004 07:32:29 -0000
Mailing-List: contact dev-help@apr.apache.org; run by ezmlm
Precedence: bulk
List-Post:
List-Help:
List-Unsubscribe:
List-Subscribe:
Delivered-To: mailing list dev@apr.apache.org
Received: (qmail 18811 invoked by uid 99); 28 Sep 2004 07:32:29 -0000
X-ASF-Spam-Status: No, hits=0.0 required=10.0
tests=
X-Spam-Check-By: apache.org
Received-SPF: pass (hermes.apache.org: local policy)
X-MimeOLE: Produced By Microsoft Exchange V6.5.7226.0
Content-class: urn:content-classes:message
MIME-Version: 1.0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Subject: RE: Threads Best Practices
Date: Tue, 28 Sep 2004 09:31:30 +0200
Message-ID: <1FB4A6BBAC3AC748AFFA8E9F42A9EFBD337A38@hunt.ericom.local>
X-MS-Has-Attach:
X-MS-TNEF-Correlator:
Thread-Topic: Threads Best Practices
Thread-Index: AcSlHRFOfbulyCRSSO6SVKRjl2+x1wACoFBw
From: "Dror Shilo"
To: "David Barrett"
Cc:
X-Virus-Checked: Checked
X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N
1) you can put null
2) see apr samples
void * APR_THREAD_FUNC ThreadProc(apr_thread_t *, void *context)
{
}
3) use
apr_os_thread_current()
4) distroy the pool
apr_thread_join is not needed if you now that the thread has ended.
5) use apr_sleep()
Dror Shilo
-----Original Message-----
From: David Barrett [mailto:dbarrett@quinthar.com]
Sent: Tuesday, September 28, 2004 7:36 AM
To: dev@apr.apache.org
Subject: Threads Best Practices
Hi there, I'm really starting to get into APR. I was able to port to =
APR
mutexes without a hitch. However, I'm a bit confused on threads, and =
I'd
appreciate any direction you can offer:
=20
1) What should I do with "apr_threadattr_t"? Need I create one, or can =
I
pass NULL for that field into "apr_thread_create"? If I need to create =
one,
do I need to do anything with it, or can I use it with its default =
state?
2) What's the proper way to declare an "apr_start_thread_t" function? =
Is
this what I'm supposed to do?
# void* ThreadProc( apr_thread_t* thread, void* data ) { }
# void foo( )
# {
# ...
# apr_thread_create(
# &thread,=20
# attr,=20
# (apr_thread_start_t)ThreadProc,=20
# (void*)data,=20
# pool
# );
# }
3) What's the portable equivalent to Win32's "GetCurrentThreadId( )"? =
I'd
like to associate some data with the thread, and then query it down the
road. Currently I use "GetCurrentThreadId( )" in conjunction with my =
own
global map. What I'd like to do us "apr_thread_data_get( )" to just =
query
the current thread's data, but it looks like I need to know the thread's
handle. Is there any way to look up the handle for the current thread, =
or
query the data of the current thread without knowing its handle?
4) What's the proper way to clean up a thread? I'm new to the whole =
"pool"
paradigm; do I simply destroy the pool I used to create the thread and =
its
attribute? I assume I need to "apr_thread_join( )" on that thread =
first,
correct?
5) What's the portable equivalent to Win32's "Sleep( )" function? I see
there is "apr_thread_yield( )", but that's not quite the same. I'd like =
to
explicitly sleep the thread for some period; can APR do this?
Thanks for all your help, and the excellent library!
-david
PS: Is there any more-accessible form of the dev@apr.apache.org archives
than what's posted up on http://apr.apache.org/mail/dev/? I'm finding =
it
difficult to search that effectively. Alternatively, can you recommend =
any
better tools for searching the archives than "grep" and "vi"? Like...
Google? :)