Re: Question about threads which share a function
- From: Daniel Pitts <newsgroup.spamfilter@xxxxxxxxxxxxxxxxxxx>
- Date: Wed, 02 Jun 2010 10:23:46 -0700
On 6/2/2010 8:47 AM, Joe wrote:
I have a function defined as void foo(int* pIn, int* pOut). The functionThe danger exists only you use static data, or if pIn/pOut of one invocation overlap with pIn or pOut of another (in which case, which thread's input/output wins over whose).
gets some data via pointer pIn and calculates some output data which is
written to the array pointed to by pOut. In the calculation of the
output, some local variables defined in foo are used.
If I have two or more threads executing and these threads use foo, are
there any risks
that something might go wrong; like the output being screwed up and
deviating from what is expected?
If you know that none of the pIn and pOut are ever overlapping, and you know that you aren't using global data, you should be fine.
For example, strtok actually uses a static variable to keep track of state, so it is *not* thread-safe. strcpy on the other hand, is (assuming you're not passing in shared char *'s)
--
Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>
.
- Follow-Ups:
- Re: Question about threads which share a function
- From: robertwessel2@xxxxxxxxx
- Re: Question about threads which share a function
- References:
- Prev by Date: Re: Question about threads which share a function
- Next by Date: Re: Question about threads which share a function
- Previous by thread: Re: Question about threads which share a function
- Next by thread: Re: Question about threads which share a function
- Index(es):
Relevant Pages
|