Python论坛  - 讨论区

标题:[python-chinese] 重做我的设计

2006年05月19日 星期五 20:59

吴俊玉 wujunyu at gmail.com
Fri May 19 20:59:57 HKT 2006

现在在重做我的设计,不过设计上有一关过不了。
我的坦克是个线程类,有个函数forward判断方向后,前进一格
另外主线程处理碰撞检测,当检测到碰撞时,产生一个command,然后调用command 执行tank类的onCollision函数。

但是由于两个线程要访问坦克类的direction属性。
导致错误

我现在希望坦克类能够对自己的行为负责,但多线程环境下我真不知道该如何设计,还往高手指点一下多线程环境下的设计
推荐两本书或网络材料也可以

谢谢了先
-- 
北京市海淀区中软国际
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060519/59306b86/attachment.htm

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2006年05月20日 星期六 01:08

yi huang yi.codeplayer at gmail.com
Sat May 20 01:08:11 HKT 2006

主线程处理碰撞检测, 只需要读坦克类的direction属性么?应该不会有问题吧

On 5/19/06, 吴俊玉 <wujunyu at gmail.com> wrote:
>
>
> 现在在重做我的设计,不过设计上有一关过不了。
> 我的坦克是个线程类,有个函数forward判断方向后,前进一格
> 另外主线程处理碰撞检测,当检测到碰撞时,产生一个command,然后调用command 执行tank类的onCollision函数。
>
> 但是由于两个线程要访问坦克类的direction属性。
> 导致错误
>
> 我现在希望坦克类能够对自己的行为负责,但多线程环境下我真不知道该如何设计,还往高手指点一下多线程环境下的设计
> 推荐两本书或网络材料也可以
>
> 谢谢了先
> --
> 北京市海淀区中软国际
>
> _______________________________________________
> python-chinese
> Post: send python-chinese at lists.python.cn
> Subscribe: send subscribe to python-chinese-request at lists.python.cn
> Unsubscribe: send unsubscribe to  python-chinese-request at lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese
>
>


-- 
http://codeplayer.blogbus.com/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060520/47eec2e1/attachment.html

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2006年05月20日 星期六 09:16

flyaflya flyaflya at gmail.com
Sat May 20 09:16:09 HKT 2006

为什么要用多线程?只会增加麻烦

On 5/20/06, yi huang <yi.codeplayer at gmail.com> wrote:
>
> 主线程处理碰撞检测, 只需要读坦克类的direction属性么?应该不会有问题吧
>
> On 5/19/06, 吴俊玉 <wujunyu at gmail.com> wrote:
>
> >
> > 现在在重做我的设计,不过设计上有一关过不了。
> > 我的坦克是个线程类,有个函数forward判断方向后,前进一格
> > 另外主线程处理碰撞检测,当检测到碰撞时,产生一个command,然后调用command 执行tank类的onCollision函数。
> >
> > 但是由于两个线程要访问坦克类的direction属性。
> > 导致错误
> >
> > 我现在希望坦克类能够对自己的行为负责,但多线程环境下我真不知道该如何设计,还往高手指点一下多线程环境下的设计
> > 推荐两本书或网络材料也可以
> >
> > 谢谢了先
> > --
> > 北京市海淀区中软国际
> >
> > _______________________________________________
> > python-chinese
> > Post: send python-chinese at lists.python.cn
> > Subscribe: send subscribe to python-chinese-request at lists.python.cn
> > Unsubscribe: send unsubscribe to
> > python-chinese-request at lists.python.cn
> > Detail Info: http://python.cn/mailman/listinfo/python-chinese
> >
> >
>
>
> --
> http://codeplayer.blogbus.com/
>
> _______________________________________________
> python-chinese
> Post: send python-chinese at lists.python.cn
> Subscribe: send subscribe to python-chinese-request at lists.python.cn
> Unsubscribe: send unsubscribe to  python-chinese-request at lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese
>
>


-- 
http://www.flyaflya.com powered by pygame+python
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060520/173c3655/attachment.html

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2006年05月20日 星期六 11:27

吴俊玉 wujunyu at gmail.com
Sat May 20 11:27:15 HKT 2006

主线程会调用坦克类的onCollision方法

坦克线程类有个run方法

两个同时处理坦克类有问题,onCollision会改变坦克类的状态。

//-----------------------------------------------------------
总之是出现竞争状态,想学学面向对象环境的多线程并发程序设计
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060520/196d6c4a/attachment.htm

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2006年05月20日 星期六 12:54

yi huang yi.codeplayer at gmail.com
Sat May 20 12:54:48 HKT 2006

那你让坦克自己去调用 onCollision 方法,主线程给他个消息就行了。

On 5/20/06, 吴俊玉 <wujunyu at gmail.com> wrote:
>
> 主线程会调用坦克类的onCollision方法
>
> 坦克线程类有个run方法
>
> 两个同时处理坦克类有问题,onCollision会改变坦克类的状态。
>
> //-----------------------------------------------------------
> 总之是出现竞争状态,想学学面向对象环境的多线程并发程序设计
>
> _______________________________________________
> python-chinese
> Post: send python-chinese at lists.python.cn
> Subscribe: send subscribe to python-chinese-request at lists.python.cn
> Unsubscribe: send unsubscribe to  python-chinese-request at lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese
>
>


-- 
http://codeplayer.blogbus.com/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060520/5ea06ef2/attachment.htm

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2006年05月20日 星期六 15:16

吴俊玉 wujunyu at gmail.com
Sat May 20 15:16:20 HKT 2006

不用多线程,我倒想听听高见!

当然 我也不希望你在回答我的问题之前没有了解我的设计目标:
我的系统模仿RoboCode
它提供接口给用户以编写脚本,控制 坦克执行。
我的保证对所有的坦克基本公平。
//--------------------------------------------------------
使用消息的方式我想过,不过当时的想法是要为每个坦克 线程使用command模式。
不过好像windows消息队列是每个线程独立的。
其实即使这样还是有点问题的,可以实现,但实现方式不够优雅!
我必须在消息中指明在时间地点发生 了碰撞.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060520/c026c934/attachment.htm

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2006年05月20日 星期六 17:12

yi huang yi.codeplayer at gmail.com
Sat May 20 17:12:55 HKT 2006

我那个就没有使用线程,不过使用了stackless的协作"线程"   :) 。
另外还可以看看 SimPy ,是通过 ganerater 实现类似的协作线程。

说实话,我现在确实不是很清楚你目前具体是如何设计的,也许你可以写份详尽的文档描述描述?

On 5/20/06, 吴俊玉 <wujunyu at gmail.com> wrote:
>
> 不用多线程,我倒想听听高见!
>
> 当然 我也不希望你在回答我的问题之前没有了解我的设计目标:
> 我的系统模仿RoboCode
> 它提供接口给用户以编写脚本,控制 坦克执行。
> 我的保证对所有的坦克基本公平。
> //--------------------------------------------------------
> 使用消息的方式我想过,不过当时的想法是要为每个坦克 线程使用command模式。
> 不过好像windows消息队列是每个线程独立的。
> 其实即使这样还是有点问题的,可以实现,但实现方式不够优雅!
> 我必须在消息中指明在时间地点发生 了碰撞.
>
>
> _______________________________________________
> python-chinese
> Post: send python-chinese at lists.python.cn
> Subscribe: send subscribe to python-chinese-request at lists.python.cn
> Unsubscribe: send unsubscribe to  python-chinese-request at lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese
>
>


-- 
http://codeplayer.blogbus.com/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060520/df603bd1/attachment.html

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2006年05月20日 星期六 19:26

吴俊玉 wujunyu at gmail.com
Sat May 20 19:26:53 HKT 2006

晕,算我说漏嘴了,本质上有多大差别?
我原先是考虑过coroutine的
只不过是更轻量级的并发执行单位而已。


我想过两种方法
一种就是huangyi 提到的串行化,但我实在想不到办法能够不保存碰撞时的坦克状态
另一种就是线程的同步,但我发现一般的临界区,互斥量等似乎无法解决我的问题。

我想也许我可以使用读写锁的方式处理我所遇到的问题。所以我参考了数据库的并发过程,现有两个问题拿出来和大家分享讨论,与python无关,但都是程序设计的问题了。
1,有没有办法模拟实现原子操作?起码别的线程不能访问,而该原子操作又要相对独立,不要和别的线程耦合度太高了――例如使用了互斥量。
2,如何实现读写锁?
     线程a对数据加了读锁,则别的线程都可以对它加读锁,但没有线程可以加写锁
     加了写锁则没有线程可以在加锁


-- 
北京市海淀区中软国际
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060520/c9660e40/attachment.html

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2006年05月20日 星期六 19:30

吴俊玉 wujunyu at gmail.com
Sat May 20 19:30:11 HKT 2006

或许我该参考一下stackless,不过原谅我的死脑筋。
我想我的方法能够优雅的解决问题
我不介意在第三版的时候尝试使用stackless,
但是现在不行
:)


-- 
北京市海淀区中软国际
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060520/1c236505/attachment.html

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2006年05月21日 星期日 00:37

Cyril_Gmail terry6394 at gmail.com
Sun May 21 00:37:27 HKT 2006

google了一下,没有搞明白stackless什么意思。
哪位,来个简单的中文介绍

On 5/20/06, 吴俊玉 <wujunyu at gmail.com> wrote:
>
> 或许我该参考一下stackless,不过原谅我的死脑筋。
> 我想我的方法能够优雅的解决问题
> 我不介意在第三版的时候尝试使用stackless,
> 但是现在不行
> :)
>
>
> --
> 北京市海淀区中软国际
>
> _______________________________________________
> python-chinese
> Post: send python-chinese at lists.python.cn
> Subscribe: send subscribe to python-chinese-request at lists.python.cn
> Unsubscribe: send unsubscribe to  python-chinese-request at lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese
>
>


-- 
编译人生!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060521/ee10817c/attachment.html

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2006年05月21日 星期日 00:40

yi huang yi.codeplayer at gmail.com
Sun May 21 00:40:54 HKT 2006

我刚才不就发了一帖?

On 5/21/06, Cyril_Gmail <terry6394 at gmail.com> wrote:
>
> google了一下,没有搞明白stackless什么意思。
> 哪位,来个简单的中文介绍
>
> On 5/20/06, 吴俊玉 <wujunyu at gmail.com> wrote:
>
> > 或许我该参考一下stackless,不过原谅我的死脑筋。
> > 我想我的方法能够优雅的解决问题
> > 我不介意在第三版的时候尝试使用stackless,
> > 但是现在不行
> > :)
> >
> >
> > --
> > 北京市海淀区中软国际
> >
>
> _______________________________________________
> python-chinese
> Post: send python-chinese at lists.python.cn
> Subscribe: send subscribe to python-chinese-request at lists.python.cn
> Unsubscribe: send unsubscribe to   python-chinese-request at lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese
>
>
>
>
> --
> 编译人生!
>
> _______________________________________________
> python-chinese
> Post: send python-chinese at lists.python.cn
> Subscribe: send subscribe to python-chinese-request at lists.python.cn
> Unsubscribe: send unsubscribe to  python-chinese-request at lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese
>
>


-- 
http://codeplayer.blogbus.com/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060521/62ec3a1e/attachment-0001.htm

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2006年05月21日 星期日 00:51

swordsp sparas2006 at gmail.com
Sun May 21 00:51:54 HKT 2006

原子操作:
一个线程安全的锁变量(对于python,threading.Lock),操作开始前上锁,结束后释放。
(不是很清楚你说的"和别的线程耦合"是什么意思,不过这样的实现肯定是没有任何问题的,除非你需要的并不是通常意义上的"原子操作")

读写锁:
需要两个计数器,分别对应"当前读者"和"等待写者"的数量。
需要有两个条件变量(对于python,threading.Condition),分别用来block和notify读者与写者。
另外对于每个操作都要维护一个临界区以保证其原子性,所以还需要一个锁变量。
基本上就是这样吧。

其实我觉得读写锁这样常用的东东python标准库里早该直接支持了,java到了1.5不也终于加进去了。

另外问一下,都说python的多线程支持不好,是指性能上有问题还是实现上有bug?
从语言级别上看好像该有的都有啊。

On 5/20/06, 吴俊玉 <wujunyu at gmail.com> wrote:
>
> 晕,算我说漏嘴了,本质上有多大差别?
> 我原先是考虑过coroutine的
> 只不过是更轻量级的并发执行单位而已。
>
>
> 我想过两种方法
> 一种就是huangyi 提到的串行化,但我实在想不到办法能够不保存碰撞时的坦克状态
> 另一种就是线程的同步,但我发现一般的临界区,互斥量等似乎无法解决我的问题。
>
>
> 我想也许我可以使用读写锁的方式处理我所遇到的问题。所以我参考了数据库的并发过程,现有两个问题拿出来和大家分享讨论,与python无关,但都是程序设计的问题了。
> 1,有没有办法模拟实现原子操作?起码别的线程不能访问,而该原子操作又要相对独立,不要和别的线程耦合度太高了――例如使用了互斥量。
> 2,如何实现读写锁?
>      线程a对数据加了读锁,则别的线程都可以对它加读锁,但没有线程可以加写锁
>      加了写锁则没有线程可以在加锁
>
>
> --
> 北京市海淀区中软国际
>
> _______________________________________________
> python-chinese
> Post: send python-chinese at lists.python.cn
> Subscribe: send subscribe to python-chinese-request at lists.python.cn
> Unsubscribe: send unsubscribe to  python-chinese-request at lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060521/45647f6b/attachment.html

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2006年05月21日 星期日 03:58

swordsp sparas2006 at gmail.com
Sun May 21 03:58:57 HKT 2006

刚刚仔细想了一下,这个问题(特别是读写锁)还是比较复杂的,补充多说几句我的想法:

关于原子操作:
要保证一个操作是原子的,也就是说要保护这个操作内部操作的共享数据的安全,那么不仅这个操作自己要加锁,其他可能读写其内部共享数据的操作都要加锁。加锁本身是君子行为,然而锁这个东西防君子不防小人,不加锁的操作总可以越过这层保护。
对于没有真正的访问保护机制的python来说,"原子操作"永远只是相对的概念,别人的代码想要破坏你的操作的原子性,理论上总是可行的,你只能保证自己的代码的安全性。

关于读写锁的实现细节:
1. 临界区和condition必须用同一个锁变量。
2.
之所以用两个condition只是为了区分reader队列和writer队列,其实也有其他的实现方法,比如让线程被从队列中唤醒时自己去做判断,不过用两个队列实现更清晰也更灵活一些。
3.
除了"正在写的writer"外,"正在等待的writer"同样可以block新来的reader――否则当reader频繁并发时,writer可能一直等待下去。(这是一般意义上比较安全的行为,但是在特定情况下也可以让reader优先进入以获得更高的并发效率。)
4. 在读锁释放时,应当先唤醒writer队列(如果不为空的话),原因参见前一条,否则之前让reader等待就没有意义了。
5.
在写锁释放时,先唤醒reader或是writer都可以,不像前一条那么绝对。从效率来考虑的话,writer比起reader来往往操作更快,而且更重要。但是,在writer高并发的情况下可能会导致reader被长时间block,所以这种情况下我倾向于reader优先,这样结合前一条至少可以保证reader与writer轮流执行,不至于造成过大的不平衡性。
6.
安全的读写锁还需要防止没有获得锁的线程"凭空"释放锁,可以用一个list来保存当前所有占有锁的线程的标识符。除了使用线程自己的标识符外,还有一个办法是由锁本身主动分配一个令牌,感觉上更为灵活一些。
7.
复杂的读写锁还需要处理嵌套调用的问题,就是说一个线程也许会重复上锁,这里的实现逻辑就要取决于具体的需要了。我觉得最好还是在程序中避免这种需求,不然使用不当可能会引起死锁。

有什么疏漏还请指出。
明天试着自己写一个完整的实现看看。

On 5/21/06, swordsp <sparas2006 at gmail.com> wrote:
>
> 原子操作:
> 一个线程安全的锁变量(对于python,threading.Lock),操作开始前上锁,结束后释放。
> (不是很清楚你说的"和别的线程耦合"是什么意思,不过这样的实现肯定是没有任何问题的,除非你需要的并不是通常意义上的"原子操作")
>
> 读写锁:
> 需要两个计数器,分别对应"当前读者"和"等待写者"的数量。
> 需要有两个条件变量(对于python,threading.Condition),分别用来block和notify读者与写者。
> 另外对于每个操作都要维护一个临界区以保证其原子性,所以还需要一个锁变量。
> 基本上就是这样吧。
>
> 其实我觉得读写锁这样常用的东东python标准库里早该直接支持了,java到了1.5不也终于加进去了。
>
> 另外问一下,都说python的多线程支持不好,是指性能上有问题还是实现上有bug?
> 从语言级别上看好像该有的都有啊。
>
> On 5/20/06, 吴俊玉 <wujunyu at gmail.com> wrote:
>
> > 晕,算我说漏嘴了,本质上有多大差别?
> 我原先是考虑过coroutine的
> 只不过是更轻量级的并发执行单位而已。
>
>
> 我想过两种方法
> 一种就是huangyi 提到的串行化,但我实在想不到办法能够不保存碰撞时的坦克状态
> 另一种就是线程的同步,但我发现一般的临界区,互斥量等似乎无法解决我的问题。
>
>
> 我想也许我可以使用读写锁的方式处理我所遇到的问题。所以我参考了数据库的并发过程,现有两个问题拿出来和大家分享讨论,与python无关,但都是程序设计的问题了。
> 1,有没有办法模拟实现原子操作?起码别的线程不能访问,而该原子操作又要相对独立,不要和别的线程耦合度太高了――例如使用了互斥量。
> 2,如何实现读写锁?
>      线程a对数据加了读锁,则别的线程都可以对它加读锁,但没有线程可以加写锁
>      加了写锁则没有线程可以在加锁
>
>
> --
> 北京市海淀区中软国际
>
> _______________________________________________
> python-chinese
> Post: send python-chinese at lists.python.cn
> Subscribe: send subscribe to python-chinese-request at lists.python.cn
> Unsubscribe: send unsubscribe to   python-chinese-request at lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060521/d16b3fdf/attachment-0001.html

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2006年05月21日 星期日 12:57

吴俊玉 wujunyu at gmail.com
Sun May 21 12:57:12 HKT 2006

谢谢swordsp给我启发

我的线程是在python中创建的,所以我得使用python中的同步方式,相比windows提供的手段,python中线程同步于互斥的手段显得单薄了些,
今天我又认真考虑了下设计我的设计:
使用线程同步方式并没有什么优势。
我的每个坦克线程都得提供读锁和写锁来互斥量个线程的访问,相比使用一个memento模式保存坦克碰撞时的状态要复杂的多。

翻了一下,也许我该看看状态机的方式能不能够给我帮助!
-- 
北京市海淀区中软国际
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060521/46e9ffa4/attachment.html

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2006年05月23日 星期二 20:49

Hou Ming Yuan houmingyuan at gmail.com
Tue May 23 20:49:45 HKT 2006

个人想法,使用多线程算是自讨苦吃,游戏里面需要同步的数据太多。
要想有多线程的优点,用stackless是一个很好的选择,它提供了一个相当于非抢占是的调度机制。


在06-5-21,吴俊玉 <wujunyu at gmail.com> 写道:
>
>  谢谢swordsp给我启发
>
>
> 我的线程是在python中创建的,所以我得使用python中的同步方式,相比windows提供的手段,python中线程同步于互斥的手段显得单薄了些,
> 今天我又认真考虑了下设计我的设计:
> 使用线程同步方式并没有什么优势。
> 我的每个坦克线程都得提供读锁和写锁来互斥量个线程的访问,相比使用一个memento模式保存坦克碰撞时的状态要复杂的多。
>
> 翻了一下,也许我该看看状态机的方式能不能够给我帮助!
> --
> 北京市海淀区中软国际
>
> _______________________________________________
> python-chinese
> Post: send python-chinese at lists.python.cn
> Subscribe: send subscribe to python-chinese-request at lists.python.cn
> Unsubscribe: send unsubscribe to  python-chinese-request at lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060523/4831089e/attachment.htm

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2006年05月23日 星期二 21:04

yi huang yi.codeplayer at gmail.com
Tue May 23 21:04:36 HKT 2006

关键是这个项目确实需要强占式的调度,
不过stackless也可以限制tasklet运行的指令数,运行了N个指令后就挂起该tasklet,不过好象没发现有分时的调度方法。

我想这东西还有个大问题就是需要限制用户编写的python程序的权限,不准写文件,有些module不能import,有些函数不准调用等等 ...

一个坦克一个线程的另一个问题是:如果要做成online,很多用户就不好办了,操作系统上能分配的线程数量貌似并不多。

On 5/23/06, Hou Ming Yuan <houmingyuan at gmail.com> wrote:
>
> 个人想法,使用多线程算是自讨苦吃,游戏里面需要同步的数据太多。
> 要想有多线程的优点,用stackless是一个很好的选择,它提供了一个相当于非抢占是的调度机制。
>
>
> 在06-5-21,吴俊玉 <wujunyu at gmail.com> 写道:
> >
> >  谢谢swordsp给我启发
>
>
> 我的线程是在python中创建的,所以我得使用python中的同步方式,相比windows提供的手段,python中线程同步于互斥的手段显得单薄了些,
> 今天我又认真考虑了下设计我的设计:
> 使用线程同步方式并没有什么优势。
> 我的每个坦克线程都得提供读锁和写锁来互斥量个线程的访问,相比使用一个memento模式保存坦克碰撞时的状态要复杂的多。
>
> 翻了一下,也许我该看看状态机的方式能不能够给我帮助!
> --
> 北京市海淀区中软国际
>
> _______________________________________________
> python-chinese
> Post: send python-chinese at lists.python.cn
> Subscribe: send subscribe to python-chinese-request at lists.python.cn
> Unsubscribe: send unsubscribe to  python-chinese-request at lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese
>
>
>
> _______________________________________________
> python-chinese
> Post: send python-chinese at lists.python.cn
> Subscribe: send subscribe to python-chinese-request at lists.python.cn
> Unsubscribe: send unsubscribe to  python-chinese-request at lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese
>
>


-- 
http://codeplayer.blogbus.com/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060523/799ea48d/attachment-0001.htm

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2006年05月23日 星期二 21:24

吴俊玉 wujunyu at gmail.com
Tue May 23 21:24:38 HKT 2006

不错,我也发现不能抢占,必须完全控制线程的执行。
因此我尝试使用petri nets来设计并发过程,设计搞出来了,还不一定能编程实现。

关系好复杂,当然了这是个人能力问题,只能继续努力了。
petri nets 还没验证是不是正确。
。。。

-- 
北京市海淀区中软国际
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060523/417d72ea/attachment.html

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2006年05月23日 星期二 21:27

yi huang yi.codeplayer at gmail.com
Tue May 23 21:27:28 HKT 2006

坦克的逻辑由用户编写,不抢占怎么行?用户写死循环怎么办?

On 5/23/06, 吴俊玉 <wujunyu at gmail.com> wrote:
>
> 不错,我也发现不能抢占,必须完全控制线程的执行。
> 因此我尝试使用petri nets来设计并发过程,设计搞出来了,还不一定能编程实现。
>
> 关系好复杂,当然了这是个人能力问题,只能继续努力了。
> petri nets 还没验证是不是正确。
> 。。。
>
> --
> 北京市海淀区中软国际
>
> _______________________________________________
> python-chinese
> Post: send python-chinese at lists.python.cn
> Subscribe: send subscribe to python-chinese-request at lists.python.cn
> Unsubscribe: send unsubscribe to  python-chinese-request at lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese
>
>


-- 
考研还是工作  哎... !
http://codeplayer.blogbus.com/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060523/453dbbc7/attachment.htm

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2006年05月23日 星期二 21:28

吴俊玉 wujunyu at gmail.com
Tue May 23 21:28:14 HKT 2006

      我想这东西还有个大问题就是需要限制用户编写的python程序的权限,不准写文件,有些module不能import,有些函数不准调用等等
...
//---------------------------------------------------------------------------
     之前也就这个问题发过邮件,只是高手的解答我一个python门外汉暂时还不能消化。
     现在只想先把线程同步搞定了再处理了。

-- 
北京市海淀区中软国际
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060523/a2c6ac00/attachment.html

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2006年05月23日 星期二 21:40

吴俊玉 wujunyu at gmail.com
Tue May 23 21:40:49 HKT 2006

我考虑的是公平性。
所有改变坦克状态的接口函数都会阻塞当前线程,
只要不改变坦克的状态,我不在乎她死循环
只要改变了坦克的状态,就会被阻塞,重新调度

-- 
北京市海淀区中软国际
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060523/105afa50/attachment.htm

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2006年05月23日 星期二 22:24

吴俊玉 wujunyu at gmail.com
Tue May 23 22:24:14 HKT 2006

刚出去了一下,考虑了huangyi的说法,
不好意思,基础不扎实,
果然还是要抢占啊!

-- 
北京市海淀区中软国际
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060523/77f79bf4/attachment.html

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

如下红色区域有误,请重新填写。

    你的回复:

    请 登录 后回复。还没有在Zeuux哲思注册吗?现在 注册 !

    Zeuux © 2025

    京ICP备05028076号