线程上下文切换问题 [英] thread context switch question

查看:70
本文介绍了线程上下文切换问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用以下代码示例:

public byte [] Get()

{

//< =可以切换到这里??

锁定(syncLock)

{

//在Get()中做点什么。

} < br $>
}


输入方法后可能会发生线程切换,但在第一行代码之前是
在方法?我在想它。 tia


-

William Stacey,DNS MVP

Using the following code sample:
public byte[] Get()
{
// <= Possible to switch Here??
lock(syncLock)
{
//Do something in Get().
}
}

It is possible for a thread switch to happen after a method is entered, but
before the first line of code in the method? I am thinking it is. tia

--
William Stacey, DNS MVP

推荐答案

William,


是的,我相信它是。你究竟打算做什么?


-

- Nicholas Paldino [.NET / C#MVP]

- 缺刻(点)paldino = at = exisconsulting< dot> com


" William Stacey" < ST ***** @ mvps.org>在消息中写道

新闻:OW ************** @ TK2MSFTNGP11.phx.gbl ...
William,

Yes, I believe it is. What exactly are you trying to do?

--
- Nicholas Paldino [.NET/C# MVP]
- nick(dot)paldino=at=exisconsulting<dot>com

"William Stacey" <st*****@mvps.org> wrote in message
news:OW**************@TK2MSFTNGP11.phx.gbl...
使用以下代码示例:
public byte [] Get()
{
//< =可以切换到这里??
lock(syncLock)

/ /在Get()中执行某些操作。
}

在输入方法后可以进行线程切换,
但在第一行之前方法中的代码?我在想它。 tia

威廉·斯泰西,DNS MVP
Using the following code sample:
public byte[] Get()
{
// <= Possible to switch Here??
lock(syncLock)
{
//Do something in Get().
}
}

It is possible for a thread switch to happen after a method is entered, but before the first line of code in the method? I am thinking it is. tia

--
William Stacey, DNS MVP



威廉,是的,这绝对是可能。为了防止你需要

使用许多线程同步技术之一,如Monitor

class。


-

Greg Ewing [MVP]
http://www.citidc .com


" William Stacey" < ST ***** @ mvps.org>在消息中写道

新闻:OW ************** @ TK2MSFTNGP11.phx.gbl ...
William, yes, that is definitely possible. To prevent that you will have to
use one of the many thread synchronization techniques like the Monitor
class.

--
Greg Ewing [MVP]
http://www.citidc.com

"William Stacey" <st*****@mvps.org> wrote in message
news:OW**************@TK2MSFTNGP11.phx.gbl...
使用以下代码示例:
public byte [] Get()
{
//< =可以切换到这里??
lock(syncLock)

/ /在Get()中执行某些操作。
}

在输入方法后可以进行线程切换,
但在第一行之前方法中的代码?我在想它。 tia

- 威廉·史黛西,DNS MVP
Using the following code sample:
public byte[] Get()
{
// <= Possible to switch Here??
lock(syncLock)
{
//Do something in Get().
}
}

It is possible for a thread switch to happen after a method is entered, but before the first line of code in the method? I am thinking it is. tia

--
William Stacey, DNS MVP



只是想要保持防御和身材出现微妙错误的地方

出现。

谢谢。

-

William Stacey,DNS MVP


Nicholas Paldino [.NET / C#MVP]" < NI ************** @ exisconsulting.com>在消息新闻中写了

:#o ************** @ TK2MSFTNGP10.phx.gbl ...
Just trying to be defensive and figure out where to subtle errors can
appear.
Thanks.
--
William Stacey, DNS MVP

"Nicholas Paldino [.NET/C# MVP]" <ni**************@exisconsulting.com> wrote
in message news:#o**************@TK2MSFTNGP10.phx.gbl...
William,

是的,我相信它是。你究竟想做什么?

-
- Nicholas Paldino [.NET / C#MVP]
- nick(dot)paldino = at = exisconsulting< dot> com

威廉斯泰西 < ST ***** @ mvps.org>在消息中写道
新闻:OW ************** @ TK2MSFTNGP11.phx.gbl ...
William,

Yes, I believe it is. What exactly are you trying to do?

--
- Nicholas Paldino [.NET/C# MVP]
- nick(dot)paldino=at=exisconsulting<dot>com

"William Stacey" <st*****@mvps.org> wrote in message
news:OW**************@TK2MSFTNGP11.phx.gbl...
使用以下代码示例:
public byte [] Get()
{
//< =可以切换到这里??
lock(syncLock)
//
//做点什么得到()。
}


在输入方法后可以进行线程切换,
Using the following code sample:
public byte[] Get()
{
// <= Possible to switch Here??
lock(syncLock)
{
//Do something in Get().
}
}

It is possible for a thread switch to happen after a method is entered,


在方法的第一行代码之前?我在想它。 tia

威廉·斯泰西,DNS MVP
before the first line of code in the method? I am thinking it is. tia

--
William Stacey, DNS MVP




这篇关于线程上下文切换问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆