[英] locks

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

问题描述

嗨!


如果我尝试访问另一个线程锁定的变量会发生什么?我不想试图锁定它,只是试图访问它。


欢呼


-------------------------------------------------- --------------

此消息是使用IMP,Internet Messaging Program发送的。

hi!

what would happen if i try to access a variable locked by another thread? i
am not trying to obtain a lock on it, just trying to access it.

cheers

----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.

推荐答案

Ajay写道:
Ajay wrote:
如果我尝试访问另一个线程锁定的变量会发生什么?
我不是想要锁定它,只是试图访问它。
what would happen if i try to access a variable locked by another thread?
i am not trying to obtain a lock on it, just trying to access it.




如果你第一次告诉我们你实际上锁定了一个变量,那么我们可能会告诉你b $ b如果你访问它会发生什么....


一般来说:python有PIL - Python解释器锁 -

" brutally"序列化(希望)对python数据结构的所有访问 -

,例如运行多个线程,附加到同一个列表,不会导致内部列表结构混乱导致段错误等等。

这使得编程非常简单,以等待

个别线程为代价。


-

问候,


Diez B. Roggisch



If you first tell us haw you actually lock a variable, we then might be able
to tell you what happens if you access it....

And in general: python has the PIL - Python Interpreter Lock - that
"brutally" serializes (hopefully) all accesses to python data-structures -
so e.g. running several threads, appending to the same list, won''t result
in messing up the internal list structure causing segfaults or the like.
That makes programming pretty easy, at the cost of lots of waiting for the
individual threads.

--
Regards,

Diez B. Roggisch


2004年3月13日星期三14:11 +0200,Diez B. Roggisch写道:
On Wed, 2004-10-13 at 14:11 +0200, Diez B. Roggisch wrote:
Ajay写道:
Ajay wrote:
如果我尝试访问另一个线程锁定的变量会发生什么?
我不是想要锁定它,只是试图访问它。
如果你第一次告诉我们你实际上锁定了一个变量,那么我们就可以告诉你如果你访问它会发生什么......
一般来说:python有PIL - Python解释器锁 -
what would happen if i try to access a variable locked by another thread?
i am not trying to obtain a lock on it, just trying to access it.
If you first tell us haw you actually lock a variable, we then might be able
to tell you what happens if you access it....

And in general: python has the PIL - Python Interpreter Lock - that



我认为你的意思是GIL(全局解释器锁)。 PIL是优秀的Python成像库。

粗暴序列化(希望)对python数据结构的所有访问 -


Nope。它不会这样做。对于访问整数这样的项目你可能很好,但对于像列表,词典,类

属性等等,你可以自己动手。 GIL只确保两个

线程不会同时执行Python字节码。它锁定了

Python *解释器*,而不是你的程序或数据结构。

所以例如运行多个线程,附加到同一个列表,不会导致搞乱内部列表结构导致段错误等。


没错,你不会得到段错误。但是,你可能会得到一个

的追溯或损坏的数据。

这使编程非常简单,代价是等待单个线程。



I think you mean the GIL (Global Interpreter Lock). PIL is the
excellent Python Imaging Library.
"brutally" serializes (hopefully) all accesses to python data-structures -
Nope. It doesn''t do this. For access to items such as integers you are
probably fine, but for things like lists, dictionaries, class
attributes, etc, you''re on your own. The GIL only ensures that two
threads won''t be executing Python bytecode simultaneously. It locks the
Python *interpreter*, not your program or data structures.
so e.g. running several threads, appending to the same list, won''t result
in messing up the internal list structure causing segfaults or the like.
True, you won''t get segfaults. However, you may very well get a
traceback or mangled data.
That makes programming pretty easy, at the cost of lots of waiting for the
individual threads.




Python中的线程非常简单,但肯定不是那么简单。并且

只是为了确定,导入PIL不会帮助你在这里< wink> ;.


问候,

Cliff


-

Cliff Wells< cl ************ @ comcast.net>



Threading in Python is pretty easy, but certainly not *that* easy. And
just to be certain, importing PIL won''t help you here either <wink>.

Regards,
Cliff

--
Cliff Wells <cl************@comcast.net>


Diez B. Roggisch写道:
Diez B. Roggisch wrote:
一般来说:python有PIL - Python解释器锁 -
And in general: python has the PIL - Python Interpreter Lock -




锁通常称为GIL(全局解释器锁)。请参阅:

http://docs.python。 org / api / threads.html


PIL是别的东西:

http://www.google.com/search?q=PIL


< ; / F>



the lock is usually known as GIL (Global Interpreter Lock). see:

http://docs.python.org/api/threads.html

PIL is something else:

http://www.google.com/search?q=PIL

</F>


这篇关于锁的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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