CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Mar 2002
    Posts
    44

    Is Send() in SOcket class thread safe?

    I would like to know if the Send() method in Socket class thread safe. THat mean, if two different objects happen to call mySocket.Send(..) on the same socket at the same time, will there be any problem in that?

    I've read that in TCPClient, the GetStream class can be locked:
    lock (myClient.getStream)


    but how about in the Socket class for the Send() method?

  2. #2
    Join Date
    Jun 2002
    Location
    Philadelphia, PA
    Posts
    85
    According to the documentation, here is what is said about System.Net.Sockets.Socket:

    Thread Safety
    Any public static (Shared in Visual Basic) members of this type are safe for multithreaded operations. Any instance members are not guaranteed to be thread safe.

  3. #3
    Join Date
    Mar 2002
    Posts
    44
    i read that too, but did not understand. public static members means wut? Instance members is created in this way rite:

    public Socket mysock;


    Is it? then how bout public static members? do i just put a static keyword in it it?

  4. #4
    Join Date
    Jun 2002
    Location
    Philadelphia, PA
    Posts
    85
    You'd used the static modifer. For example:

    Code:
    public static Socket mySock;
    You could also synchornize any functions which use it to make sure they do collide.

  5. #5
    Join Date
    May 2002
    Location
    Atlanta,GA
    Posts
    262
    Originally posted by CPCericola
    You'd used the static modifer. For example:

    Code:
    public static Socket mySock;
    You could also synchornize any functions which use it to make sure they do collide.
    This would not make the Socket thread safe. The quote says that any public static members are thread safe. Simply making the Socket static doesn't have any effect on its members.

    And I'm guessing that Send() is not a Thread safe operation on Sockets. If it was I would imagine they would say something about it.
    Jared

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured