public void Send(Packet packet)
{
lock (this)
{
Console.WriteLine("packet send start... thread - {0}", Thread.CurrentThread.ManagedThreadId);
this.Send(buffer, 0, buffer.Length, SocketFlags.None, out this.error);
Console.WriteLine("packet send end... thread - {0}", Thread.CurrentThread.ManagedThreadId);
}
}
c#에서 thread-safe 한 함수를 만들려고 이런식으로 lock을 사용해서 함수를 만들어놨거든?
평소에는 로그가 이렇게 나와
packet send start... thread - 26
packet send end... thread - 26
packet send start... thread - 26
packet send end... thread - 26
그런데 가끔씩
packet send start... thread - 17
packet send start... thread - 29
이렇게 나오거든..?
분명 lock으로 감쌋는데 왜 lock을 뚫고 또다른 쓰레드가 진입할 수 있는거지?
이거 c#의 버그인가?
댓글 0