锁定线程 [英] Locking threads

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

问题描述




我正在开发一个CMS,我希望能够缓存网站树。在
共享内存中的多维数组(太多的sql调用

否则)。当有人在树中添加项目时,我需要能够从共享内存中读取数组中的
,添加新项目,然后将其写入

返回共享内存.....所有在一个原子动作中。


我做了大量的研究,没有使用像

eaccelerator或mmcache这样的东西我我坚持使用PHP信号量,即便如此

似乎不是线程安全的,只是处理安全(如果我是错误的话,请纠正我) - 和b $ b错误) - 和然后我被限制在* nix系统。


有没有办法创建一个方法来完成上面的工作

on * nix and Windows,无论是多线程还是单线程?


谢谢,


Jim。

解决方案

Jim写道:





我正在开发一个CMS,我希望能够缓存网站树。在
共享内存中的多维数组(太多的sql调用

否则)。当有人在树中添加项目时,我需要能够从共享内存中读取数组中的
,添加新项目,然后将其写入

返回共享内存.....所有在一个原子动作中。


我做了大量的研究,没有使用像

eaccelerator或mmcache这样的东西我我坚持使用PHP信号量,即便如此

似乎不是线程安全的,只是处理安全(如果我是错误的话,请纠正我) - 和b $ b错误) - 和然后我被限制在* nix系统。


有没有办法创建一个方法来完成上面的工作

on * nix and Windows,无论是多线程还是单线程?


谢谢,


Jim。


Jim,


使用数据库。周围有数十个使用数据库;如果

正确实施,它们可以非常有效。


-

=========== =======

删除x来自我的电子邮件地址

Jerry Stuckle

JDS计算机培训公司
js ******* @ attglobal.net

==================


我正在开发一个CMS,我希望能够缓存网站树。 in


共享内存中的多维数组(太多的sql调用

否则)。当有人在树中添加项目时,我需要能够从共享内存中读取数组中的
,添加新项目,然后将其写入

返回共享内存.....所有在一个原子动作。


我已经做了大量研究而没有使用像

eaccelerator或mmcache这样的东西我被卡住了使用PHP信号量,即使那时,
看起来不是线程安全的,只是处理安全(如果我是错误的话,请纠正我) - 然后我'限于* nix系统。


有没有办法创建一个方法来完成上面的工作

on * nix和Windows,它是多线程还是单线程?


Jim,


使用数据库。周围有数十个使用数据库;如果

正确实施,它们可以非常有效。



嗨Jerry,


如果我能想到一种有效的方式,那么我会坚持

db only,但我看不出怎么样。例如,我有一个表格

代表网站的结构,所以简单地说每个记录

有一个id和一个父id。为了构建一个左手导航,我可能需要

调用3或4个sql语句来获取我需要的所有数据,我希望

以避免这样做可能。


谢谢,


吉姆。




" Jim" < ji *** @ yahoo.com在留言中写道

news:11 ********************* @ m3g2000hsh.googlegrou ps。 com ...


>使用数据库。周围有数十个使用数据库;如果正确实施,它们可以非常有效。



嗨Jerry,


如果我能想到一种有效的方法,那么我会坚持

db only,但我看不出怎么样。例如,我有一个表格

代表网站的结构,所以简单地说每个记录

有一个id和一个父id。为了构建一个左手导航,我可能需要

调用3或4个sql语句来获取我需要的所有数据,我希望

以避免这样做可能。



过早优化?

三个或四个sql调用是亚毫秒(一旦操作系统有

*缓存*你的数据库工作集)。将此与TCP / IP数据包交换的数十或两美元毫秒进行比较,或者从.au,这需要几百毫秒。

您是否进行了任何基准测试以证明sql调用确实存在问题?


-

Richard。


Hi,

I''m developing a CMS and I''d like to be able cache the site "tree" in
a multi-dimensional array in shared memory (far too many sql calls
otherwise). When someone adds an item in the tree I need to be able to
read in the array from shared memory, add the new item, then write it
back to shared memory.....all in one atomic action.

I''ve done plenty of research and short of using something like
eaccelerator or mmcache I''m stuck with PHP semaphores which even then
don''t appear to be thread safe, only process safe (correct me if I''m
wrong) - and then I''m restricted to *nix systems.

Is there any way to create a method of doing the above which will work
on *nix and Windows, whether it''s multi-threaded or single-threaded?

Thanks,

Jim.

解决方案

Jim wrote:

Hi,

I''m developing a CMS and I''d like to be able cache the site "tree" in
a multi-dimensional array in shared memory (far too many sql calls
otherwise). When someone adds an item in the tree I need to be able to
read in the array from shared memory, add the new item, then write it
back to shared memory.....all in one atomic action.

I''ve done plenty of research and short of using something like
eaccelerator or mmcache I''m stuck with PHP semaphores which even then
don''t appear to be thread safe, only process safe (correct me if I''m
wrong) - and then I''m restricted to *nix systems.

Is there any way to create a method of doing the above which will work
on *nix and Windows, whether it''s multi-threaded or single-threaded?

Thanks,

Jim.

Jim,

Use a database. There are dozens around which use databases; if
implemented properly they can be quite efficient.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================


I''m developing a CMS and I''d like to be able cache the site "tree" in

a multi-dimensional array in shared memory (far too many sql calls
otherwise). When someone adds an item in the tree I need to be able to
read in the array from shared memory, add the new item, then write it
back to shared memory.....all in one atomic action.

I''ve done plenty of research and short of using something like
eaccelerator or mmcache I''m stuck with PHP semaphores which even then
don''t appear to be thread safe, only process safe (correct me if I''m
wrong) - and then I''m restricted to *nix systems.

Is there any way to create a method of doing the above which will work
on *nix and Windows, whether it''s multi-threaded or single-threaded?

Jim,

Use a database. There are dozens around which use databases; if
implemented properly they can be quite efficient.

Hi Jerry,

If I could think of a way of doing it efficiently then I''d stick with
db only, but I can''t see how. For example, I have a table which
represents the structure of the site, so to put it simply each record
has an id and a parent id. To build say a left hand nav I may need to
call 3 or 4 sql statements to get all the data I need which I''d like
to avoid doing if possible.

Thanks,

Jim.



"Jim" <ji***@yahoo.comwrote in message
news:11*********************@m3g2000hsh.googlegrou ps.com...

>Use a database. There are dozens around which use databases; if
implemented properly they can be quite efficient.


Hi Jerry,

If I could think of a way of doing it efficiently then I''d stick with
db only, but I can''t see how. For example, I have a table which
represents the structure of the site, so to put it simply each record
has an id and a parent id. To build say a left hand nav I may need to
call 3 or 4 sql statements to get all the data I need which I''d like
to avoid doing if possible.

Premature optimization?

Three or four sql calls is sub-millisecond (once the operating system has
*cached* your database working set for you). Compare this to the tens of
milliseconds for a TCP/IP packet exchange or, from over here in .au,
hundreds of milliseconds.

Have you done any benchmarking to prove the sql calls are really a problem?

--
Richard.


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

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