Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
|
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 4th, 2005, 02:57 PM
Friend of Wrox
 
Join Date: Jul 2004
Posts: 623
Thanks: 0
Thanked 1 Time in 1 Post
Default synchronization and lock statement

Hi Experts,
please look at this example,can someone tell me what is the scenario behind it,
Code:
class MyClass 
{
    private string m_sString = null;

    public MyClass()
    {
        m_sString = "Hello";
    }

    void GetString1()
    {
        lock (this)
        {
            return m_sString;
        }
    }

    void GetString2()
    {
        lock (m_sString)
        {
            return m_sString;
        }
    }
}
I know another thread can't access GetString1,I don't know what is the difference between lock(this) and lock(m_sString)?
Thanks in advance.

_____________________________
Mehdi.
software engineering student.
Looking for a good job for summer 2005.
__________________
_____________
<font color=\"teal\"><font size=\"1\"><b>Mehdi.
software student.</b></font id=\"size1\"></font id=\"teal\">
 
Old February 10th, 2005, 06:10 AM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 326
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to Santhi Send a message via MSN to Santhi
Default

void GetString1()
    {
        lock (this)
        {
            return m_sString;
        }
    }
How Void function will return data..







Similar Threads
Thread Thread Starter Forum Replies Last Post
data synchronization abdulweb General .NET 0 August 26th, 2007 12:20 AM
--Javascript Synchronization-- tal Javascript 2 June 29th, 2007 11:33 AM
Access / MySQL Synchronization echovue Access VBA 4 December 5th, 2005 02:49 PM
XML Synchronization prashant_dnmmkpk Biztalk 0 January 17th, 2005 09:16 AM
Synchronization Problem bveerendrakumar Pro VB 6 2 July 10th, 2003 05:18 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.