Please take our Survey
logo       

Choosing A Webhost:
A web hosting service is a type of Internet hosting service that allows individuals and organizations to provide their own website accessible via the World Wide Web. Web hosts are companies that provide space on a server they own for use by their clients as well as providing Internet connectivity, typically in a data center. Web hosts can also provide data center space and connectivity to the Internet for servers they do not own to be located in their data center, called colocation. more...

RE: Threads Best Practices: msg#00188

apache.apr.devel

Subject: RE: Threads Best Practices

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@xxxxxxxxxxxx]
Sent: Tuesday, September 28, 2004 7:36 AM
To: dev@xxxxxxxxxxxxxx
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,
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@xxxxxxxxxxxxxx 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? :)




<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

Recently Viewed:
ide.eclipse.wtp...    bug-tracking.ro...    xfree86.cvs/200...    lisp.wxcl.devel...    file-systems.ar...    kde.devel.kwrit...    jakarta.jetspee...    qnx.openqnx.dev...    drivers.openib/...    ports.xbox.deve...    gis.gdal.devel/...    netbsd.ports.ma...    ubuntu.marketin...    systemtap/2005-...    web.omniweb/200...    mail.qmail.ldap...    hardware.soekri...    os.netbsd.devel...    audio.madman.ge...    tv.freeguide-tv...    cluster.openmos...    education.ezpro...   
Home | advertise | OSDir is an inevitable website. super tiny logo

Free Magazines

Cisco News
Receive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business.
subscribe

Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field.
subscribe

The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business.
subscribe

Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company.
subscribe

Total Telecom Total Telecom is "The Economist of the communications industry".
subscribe

Navigation