On Tue, Jun 9, 2009 at 5:02 PM, Deepak sathe<[email protected]> wrote:
> I need to write one function which will share by multiple thread . this 
> function will have some shared data resources that need to protect from 
> simultinous execution of thread. I am planning to use mutex to protect my 
> shared data resourse.
>
> Now the requirement is that i wante to define mutex veriable in the function 
> itself. i dont want to make it global or declare outside and pass is to 
> function.
>
> One solution i can see is to declare mutex varible as static inside function 
> but somewhere i heard that static is not thred safe.

It's as thread safe as a global, or a variable passed in are - i.e.
none of them are unless protected by critical sections.

If it's a simple data type (i.e. not a class) then just use critical
sections around reads and writes on it as you would if you had passed
it in or declared it global.

-- 
PJH

http://shabbleland.myminicity.com/com
http://www.chavgangs.com/register.php?referer=9375

Reply via email to