寻找高效的线程同步? [英] Looking for an Efficient Thread Synchronization?

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

问题描述

在操作流媒体视频和3D内容的应用程序中,我想实现
实现mutithreading以确保适当的UI响应时间。


因为我的应用程序非常速度至关重要我想使用最有效的同步共享数据对象的
。在这种情况下会是什么?

我认为这是一个非常简单的答案,但我有点困惑

可用的不同方法。


我需要在线程之间传输的数据有相似之处:

- 数据只有一种方式(流式传输);一个线程正在写,另一个是

线程正在读取。

只有这两个线程才能访问该对象;非常简单。

- 每个周期传输的数据是图像,因此相对较大

chuncks,大约1 mb。

- 有最多每秒每个共享对象30个读/写操作。


任何答案都很赞赏(也很简单)

期待,Teis


In an application manipulating streaming video and 3D stuff I want to
implement mutithreading to ensure a decent UI response time.

Since my application is very speed critical I want to use the most efficient
synchronization of the shared data objects. What would that be in this case?
I think there''s a very simple answer to this, but I am somewhat confused by
the different methods available.

The data I need to transfer between threads share similarities:
- The data only goes one way (streaming); One thread is writing, another
thread is reading.
Only these two threads have access to the object; pretty simple.
- The data transfered per cycle are images and therefore relatively large
chuncks, approximately 1 mb.
- There are up to 30 read/write operations per shared object per second.

Any answer is appreciated (also simple ones)
Looking forward, Teis


推荐答案

您是在使用队列还是必须在每次写入之后进行读取才能进行下一次写入?


Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog
http://www.dotnetconsult.co.uk


在一个操作流媒体视频和3D内容的应用程序中我想要

实现mutithreading以确保适当的UI响应时间。


自我的应用程序on是非常速度关键我想使用最有效的同步共享数据对象的
。在这种情况下会是什么?

我认为这是一个非常简单的答案,但我有点困惑

可用的不同方法。


我需要在线程之间传输的数据有相似之处:

- 数据只有一种方式(流式传输);一个线程正在写,另一个是

线程正在读取。

只有这两个线程才能访问该对象;非常简单。

- 每个周期传输的数据是图像,因此相对较大

chuncks,大约1 mb。

- 有最多每秒每个共享对象30个读/写操作。


任何答案都很赞赏(也很简单)

期待,Teis

Are you using a queue or must each write be followed by a read before the next write can happen?

Regards

Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog
http://www.dotnetconsult.co.uk

In an application manipulating streaming video and 3D stuff I want to
implement mutithreading to ensure a decent UI response time.

Since my application is very speed critical I want to use the most efficient
synchronization of the shared data objects. What would that be in this case?
I think there''s a very simple answer to this, but I am somewhat confused by
the different methods available.

The data I need to transfer between threads share similarities:
- The data only goes one way (streaming); One thread is writing, another
thread is reading.
Only these two threads have access to the object; pretty simple.
- The data transfered per cycle are images and therefore relatively large
chuncks, approximately 1 mb.
- There are up to 30 read/write operations per shared object per second.

Any answer is appreciated (also simple ones)
Looking forward, Teis


线程同步有两种基本方法。第一个

,最常见的是锁定和阻止。另一种是基于消息的。基于消息

更快但需要更多人才。


在呼叫者和被呼叫者上设置事件。这样你就不必等待

异步调用返回,被调用者可以使用一个事件来通知完成

(也是异步)。定义EventArgs的子类来携带你的数据和

使用它们进行所有参数传递。


不要明确触发事件来调用这些方法,它太慢了。直接打电话给他们

,让每个人都这样开始,这样你就不会产生额外费用,除非你真的需要它,否则你需要花费额外费用。注意:函数是

内在阻塞。在这种情况下,你应该使用BeginInvoke()和

EndInvoke()来调用asynch但是等待响应。不是随意的

但仍然是线程安全的。


或者重写你的函数以通过asynch在EventArgs中返回它们的值

回调。我就是做这个的。但是你最好擅长编程 - 你

不能依赖固定顺序发生的事情。


委托MyMethodDelegate(.. 。);

事件MyMethodDelegate MyMethodEvent(...);

void MyMethod(...){

if(InvokeRequired){

MyMethodEvent(...);

返回;

}

//实际处理

...

}
There are two fundamental approaches to thread synchronisation. The first
and most common is lock-and-block. The other is message-based. Message-based
is faster but requires more talent.

Set up events on both caller and callee. That way you don''t have to wait for
the asynch call to return, the callee can use an event to notify completion
(also asynchronously). Define subclasses of EventArgs to carry your data and
use them for all your parameter passing.

Don''t explicitly fire events to call these methods, it''s too slow. Call them
directly and have each one start like this so you don''t incur the overhead
of asynch marshalling unless you actually need it. Note: functions are
intrinsically blocking. In this case you should use BeginInvoke() and
EndInvoke() to call asynch yet wait for the response. Not as free-wheeling
but still thread-safe.

Or rewrite your functions to return their values in EventArgs via asynch
callback. That''s what I do. But you''d better be good at programming - you
can''t depend on things happening in a fixed order.

delegate MyMethodDelegate(...);
event MyMethodDelegate MyMethodEvent(...);
void MyMethod(...) {
if (InvokeRequired) {
MyMethodEvent(...);
return;
}
//actual processing
...
}


感谢您收看我的帖子,


那里是两种不同的行为

- 在某些部分,例如阅读视频流,我需要处理每一个

单帧数据。一个队列听起来很适合这个任务。


- 在其他方面,比如渲染到UI,我只需要最新的数据。

UI有要做的事情很多,可能会问(!)数据的频率低于流提供的
,那么应该只有最后一帧。如果它比提供的更频繁地要求

,应该告诉它重复使用最后一帧。


问候,Teis

" ; Richard Blewett [DevelopMentor]" < RI ****** @ NOSPAMdevelop.com>写在

消息新闻:OR **************** @ TK2MSFTNGP11.phx.gbl ...
Thanks you for ansering my post,

there are two different behaveiours
- In some parts, such as reading the video stream, I need to process every
single frame data. A queue sounds suitable for this task.

- In other pards, such as rendering to the UI, I just need the latest data.
The UI has a lot to do and might ask(!) for the data less frequent than
offered by the stream and should then just have the last frame. If it asks
more frequent than offered, it should be told to reuse the last frame.

Regards, Teis
"Richard Blewett [DevelopMentor]" <ri******@NOSPAMdevelop.com> wrote in
message news:OR****************@TK2MSFTNGP11.phx.gbl...
你在用在
下一次写作可能发生之前,每个写入一个队列还是每个写入之后必须进行读取?



Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog
http://www.dotnetconsult.co.uk

在应用程序中操纵流媒体视频和3D的东西我想实现mutithreading以确保一个体面的UI响应时间。

由于我的应用程序速度非常快,我想使用最多
的高效同步共享数据对象。这个
案件会是什么?我认为对此有一个非常简单的答案,但我对可用的不同方法有点困惑


我需要在线程之间传输的数据有相似之处:
- 数据只有一种方式(流式传输);一个线程正在写入,另一个线程正在读取。
只有这两个线程可以访问该对象;非常简单。
- 每个周期传输的数据都是图像,因此相对较大,大约1 mb.
- 每个共享对象每秒最多有30个读/写操作。 br />
任何答案都表示赞赏(也很简单)
期待,Teis
Are you using a queue or must each write be followed by a read before the next write can happen?
Regards

Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog
http://www.dotnetconsult.co.uk

In an application manipulating streaming video and 3D stuff I want to
implement mutithreading to ensure a decent UI response time.

Since my application is very speed critical I want to use the most efficient synchronization of the shared data objects. What would that be in this case? I think there''s a very simple answer to this, but I am somewhat confused by the different methods available.

The data I need to transfer between threads share similarities:
- The data only goes one way (streaming); One thread is writing, another
thread is reading.
Only these two threads have access to the object; pretty simple.
- The data transfered per cycle are images and therefore relatively large
chuncks, approximately 1 mb.
- There are up to 30 read/write operations per shared object per second.

Any answer is appreciated (also simple ones)
Looking forward, Teis



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

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