apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Dror Shilo" <Dror.Sh...@ericom.com>
Subject RE: Threads Best Practices
Date Tue, 28 Sep 2004 07:31:30 GMT
1) you can put null
2) see apr samples

void * APR_THREAD_FUNC ThreadProc(apr_thread_t *, void *context)
3)	use

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:
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, 
#		attr, 
#		(apr_thread_start_t)ThreadProc, 
#		(void*)data, 
#		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,

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!


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? :)

View raw message