由买买提看人间百态

topics

全部话题 - 话题: threading
首页 上页 1 2 3 4 5 6 7 8 9 10 下页 末页 (共10页)
m****r
发帖数: 6639
1
来自主题: Java版 - multi-threading guru们 (转载)
我这样写
class job1 {
C obj;
job1 (C c) { obj = c; }
run() {
synchronize (obj) {
if (method2 not done) obj.wait();
obj.method1
}
}
class job2 {
run() {
synchronize (obj) {
obj.method2;
obj.set method2 done;
obj.notifyAll();
}
}
in main thread
C c = new C();
new Thread(new job1(c)).start();
new Thread(new job2(c)).start();
这个应该是本来的意思.
c******n
发帖数: 4965
2
来自主题: Java版 - 多少个thread 就算不正常?
多谢, 没有deadlock, jstack -l 可以看到
不应该是deadlock, cuz it goes away naturally after a while
不是我自己的code, 是apache cassandra
他们已经在用thread pool, 不过是unlimited, 所以我才问,
1000 个thread 的pool 是不是不可能handle 了。
正常运行, 到600 个thread 都没有问题, 之后可以ramp up 看看limit 到底是多少
p*******s
发帖数: 535
3
现在在改一个我单位系统里的一个class,里面几乎所有method都是synchronized。
我的想法是,把某些method先改成不是synchronized,如果能够确保这些method用的
class variables 是 synchronized的被读和写。这样可行吗?
如果可以,我不太确定怎么动这些class variables,是不是就改成concurrent data
type就可以了?
这样我是不是要留意下dead lock的问题?因为是各个variable各自管自己的thread
safety问题。
这个class很大,差不多3000行,我现在根本就心里发怵,不敢下手改。
如果有人对thread很熟悉,请多多指点下我,
我给发包子。
r*****l
发帖数: 2859
4
1, Find out why the synchronized methods need to access class level members.
2, If they do it in order to share data across threads, then you will need
some synchronization. You can either centralize the synchronized blocks or
externalize the data and make the data threadsafe.
3, If they do it in order to share data between different methods for one
thread, then use ThreadLocal.
S*A
发帖数: 7142
5
来自主题: Linux版 - Process and Thread

What do you mean threads within one process?
Nope, threads and process are different.
threads share process memory mapping and signal handling.
r***e
发帖数: 2000
6
来自主题: Linux版 - Process and Thread

I meant Linux thread is somewhat the same as a Linux process,
unlike OS such as Mach where multiple threads running within
one process.
This is user level for Linux, or kernel level?
I read all POSIX threads are user level?
j******o
发帖数: 82
7
来自主题: Programming版 - Windows Thread API
想自己写一个简单的Thread Pool.用过PThread和Java的Thread,看了一下MSDN的
Windows
Thread API,但好像都是C Function不知道有没有C++的Class?请指点一下,给各LINK之
类.
谢谢!
T*******i
发帖数: 4992
8
posix thread是standard。
nptl取代了linuxthread。nptl是posix thread的一个implementation。
f*******y
发帖数: 988
9
来自主题: Programming版 - 如何强制thread和cpu绑定?
我知道linux下面对process可以设定CPU mask从而达到绑定在某几个CPU上面的
但是没有找到对于thread的类似功能;我希望有thread group 1可以占某2个CPU,不要
调度到别的CPU上面去, related的data太多,怕cache performance下降
其他的几百个thread是group 2,可以分享剩下的2个CPU,随便怎么调度都可以
希望达人指点一下,有什么system call么 ( linux , PTHREAD, G++ )
c**s
发帖数: 114
10
来自主题: Programming版 - 多个thread的通信
请问有什么最好的方式做多个thread之间的实时通信?
我想最简单的办法可能是每个thread都是一个死循环,然后读或写一个所有thread共有
的类。但是这样每次读写都要加锁,会不会对性能影响很大呢?
X****r
发帖数: 3557
11
I'm not sure I understand your question -- kernel threads are what the
kernel sees, and user threads are what the applications see, so there
must be a mapping somehow, right? After all, if a piece of code is
executing, both the application and the kernel should agree on this
fact.
S**Y
发帖数: 136
12
thanks, thinking pig...
yes. u understood me.
i still dont understand "so there
why can't the CPU directly schedule the user threads instead of mapping them
to a kernel thread? why do we need this mapping?
Thanks.
S**Y
发帖数: 136
13
thanks...
does it mean that, no matter what, a user level thread has to be attached(bo
und) to a kernel thread to be scheduled? therefore, there are m:1, 1:1, m:n
models?
f******k
发帖数: 297
14
来自主题: Programming版 - thread on logical processor
is there a way in Windows to know which logical processor a thread is
running on? does it happen often that a thread is switched between different
processors by OS scheduling?
also in a hyperthreaded multicore environment, does OS have a preference to
first schedule thread on different physical processors, or it treat every
logical processor equal?
thx.
N***m
发帖数: 4460
15
来自主题: Programming版 - thread c++ 问题
I am a green hand in c++ and boost::thread. I have the following question.
Any comment is appreciated:)
Simply put, I want to manipulate a file with two threads:
one for read and one for write. When the total access number exceeds a given
limit, they just return. End of thread and main.
So in theory,read/write should be in equal probability. But I found
their behaviors tend to cluster. So the question is that: is my
observation wrong? or My understanding about mutex etc is wrong?
or anything els
t****t
发帖数: 6806
16
t1.join() means block CURRENT thread, until t1 ends. current thread is not
t1. in your example, you have 3 threads: current, t1, and t2.
s********k
发帖数: 6180
17
谢谢,current thread可以是t1吗?这个current thread指的是正在运行的thread?
c*******9
发帖数: 6411
18
thanks.
i changed Display.getDefault().asyncExec to SwingUtilities.invokeLater but
get the same.
could you elaborate on how i can update text.setText("test"), the GUI thread
is the main thread,right? how can I get back to the main thread and do the
update properly inside the widgetSelected function.
o**2
发帖数: 168
19
在Swing里,UI thread是固定的,所以可以用SwingUtilities.invokeLater()。
但在SWT里,UI thread不是固定的,所以必须用display.syncExec()。
http://www.eclipse.org/swt/faq.php#uithread
虽然这些thread-based的编程技术还在使用,但会被新的编程技术淘汰掉的,比如我开
发的FMP。
s********k
发帖数: 6180
20
python使用thread已经out了,好的架构都是用event based,python针对的应用大部分
并不需要intensive的threading,否则要拿pthread直接写还好点。
不过thread safe确实程序员需要了解,OS的基本功之一
c*********e
发帖数: 16335
21
对的。记得前段有人讨论multi-threading,说用message就可以避开multi-threading,
其实message是有其它的帮它做了multi-threading了。
d*******r
发帖数: 3299
22
github.com/noxrepo/nox-classic/blob/destiny/src/lib/threads/cooperative.cc
github.com/noxrepo/nox-classic/blob/destiny/src/lib/threads/impl.cc
几年前看过的 user space thread, C++ over C,
是 Stanford 的 OpenFlow Switch 的 controller
N********n
发帖数: 8363
23

无关,一个CPU照样MULTI-THREAD。如果这5个THREAD互相排斥锁资源,来5个
CPU也没用,还得串行。
s******u
发帖数: 501
24
什么意思?process启动之后本身就是一个main thread,你说的是thread#1和main
thread之间做sync么?这样子当然可以
i**p
发帖数: 902
25
来自主题: Programming版 - Daemon thread
My point is the process may NOT exit though main() reaches to the end of
function because other threads are running.
On the other hand, main() is started from a thread. It is POSSIBLE to
implement a system to keep the process running until all the threads exit.
A*******s
发帖数: 3942
26
刚刚开始学multi-thread programming,有个问题是,how to pass the parameters'
values into each thread? 我在每个thread调用的程序里只会用&sysparm,但是如果
每个程序都需要用到不同的参数该怎么办?
不懂X command,可以在里面加上参数么?
w*******y
发帖数: 60932
27
Hey fellow SDers
There have been a bit of Target clearance threads popping up since last week
...who am I kidding, A LOT of Target clearance thread, which is great. But
trying to keep up with each one to find great deals can be a bit much, so
this thread is simply for the consolidation and maybe moving forward the
usage of posting Target clearance deals that folks can subscribe too.
Enjoy your hunt
w*******y
发帖数: 60932
28
This thread should eventually be moved to Deal Talk and is going to be
similar to the .01 thread for Home Depot.
Please list the link to the item and if you find it in B&M or online, please
list the store name, and store number.
There has been a "cart trick" in the past that may or may not still work,
however since this is a general thread, people can post deals they find at
individual stores, and then others can see if their store offers similar
deals. If the price isn't valid in your store, ju... 阅读全帖
w*******y
发帖数: 60932
29
The Deal: Walmart B&M has many different LEGO sets on clearance for
approximately 50% of MSRP. Many of the tags on the shelf may still show
full price so you have a good chance of finding items if they haven't marked
them correctly.
This Thread: Is an attempt to provide a complete list of sets that are
marked down and a list of those that are not. I spent a couple hours at a
few different Walmarts using the obnoxiously loud price checker to find the
deals and hope to save others that hassle.... 阅读全帖
i*****f
发帖数: 578
30
来自主题: _Python版 - can not start thread
i found this artible here.
http://www.velocityreviews.com/forums/t347990-thread-limit-in-python.html
it seems not to be a language thing, since the author did the same thing in
pthread and reached the same limit as in python. he thought it might be an
os imposed limit.
it maybe simply that you are using too much system resources that it can't
support creating more threads. should you try a thread pool instead?
t*****g
发帖数: 1275
31
来自主题: Military版 - c++ thread 求助 (转载)
如果算比读还慢,起上N个thread(N=#core),每个thread死循环处理读上来的下一行。
b*w
发帖数: 14917
32
来自主题: Military版 - c++ thread 求助 (转载)
另外创建thread的数目时,也要考虑CPU本身有几个虚拟的processors,太多threads不
一定能提高效率
H*M
发帖数: 1268
33
来自主题: JobHunting版 - how to create thread-safe singleton?
Not to prevent creating multple copies of singleton(for that we will use mu
tex for that instance method or eager initilization).
By thread-safe, I mean, after the singleton is created. Two threads want to
access it and modify some data within it. It has to be synchronized right? T
hen we use mutex for each "modifying" method of this Singleton class?
H*M
发帖数: 1268
34
来自主题: JobHunting版 - 一个thread如何kill另外一个thread?
但是thread2如何能够时时刻刻监视这个flag?
l****q
发帖数: 177
35
来自主题: JobHunting版 - 一个thread如何kill另外一个thread?
楼上的概念没搞清楚
pthread_join in thread = waitpid in process
r******d
发帖数: 308
36
来自主题: JobHunting版 - multi thread复习请教
我刚准备完multithread的内容, 写出来参考一下
需要弄懂得知识点(对于所有的语言):
Synchronization, deadlock, race condictions, mutual excusive(互相排斥),
semiphore(信号), signals, multiple processing vs multiple threading。
Communication between processes or computers, IPC, pipe。Mutex(互斥)
linux:
https://computing.llnl.gov/tutorials/pthreads/
unix:
http://beej.us/guide/bgipc/output/html/multipage/index.html
c#的我只是看了C# in a nutshell 里面multithread的部分, 觉得也够用了
到现在为止就面试了两个multithread, 都是c#的
大概问了这样几个问题
(1) 怎么样start 一个 thread
(2) 写一段代码实现multit... 阅读全帖
r******d
发帖数: 308
37
来自主题: JobHunting版 - multi thread复习请教
http://en.wikipedia.org/wiki/Monitor_%28synchronization%29
在上面链接里面, 把monitor 分成了mutex 和 wait and signaling. wait and
signaling 好像就是condition varibles
我不确定的是monitor是不是每次只能够有一个thread在用cpu(monitor)? 因为在上面
的那个链接里面有说at most one thread occupies the monitor at each time
请请问一下在你看的书里面monitor是不是每次只能一个一个线程在跑?
j*****u
发帖数: 1133
38
来自主题: JobHunting版 - multi thread复习请教
没看你的链接不过我觉得意思是:
monitor:只有一个thread能够拿到lock,其他threads被block
monitor跟mutex类似,区别是monitor更轻量级一点,mutex是kernal object,因此可以
interprocess
synchronization有很多种,不同语言有不同实现但方法大同小异,建议找一个语言仔细
看看
不同方法有不同的适用范围,通常越efficient的限制越大
比如volatile,Interlock,SpinLock等non-blocking的synchronization适用范围肯定没
有monitor广,同理monitor也不像mutex/semaphare可以interprocess同步
j*****u
发帖数: 1133
39
来自主题: JobHunting版 - multi thread复习请教
不要把概念混淆
比如mutex和monitor、semaphore。。是对应的
Join只不过是block当然thread直到target thread结束
a****n
发帖数: 1887
40
来自主题: JobHunting版 - multi-threading guru们
in C++
create event
thread A------------------------
wait for event
invoke method 1
thread B------------------------
invoke method 2
set event
h*********n
发帖数: 915
41
来自主题: JobHunting版 - thread safe hash table
how to implement it?
simply using mutex on every table slot is both time and space expensive.
how to use read/write lock to solve it?
how about each slot has a thread pool? every thread can only access its own space.
c**z
发帖数: 669
42
来自主题: JobHunting版 - 请教如何保证函数时thread safe的?
如果在里面放一个 member variable, set it to true when the thread starts to
execute, and flip it when the thread returns.
请问这样可以吗
c**z
发帖数: 669
43
来自主题: JobHunting版 - 请教如何保证函数时thread safe的?
I copy and paste the code into and got the following error message. Does
anyone know what's going on?
1> c:\users\lyn\downloads\boost_1_51_0\boost_1_51_0\boost\thread\
win32\mutex.hpp(26) : see declaration of 'boost::mutex::mutex'
1> c:\users\lyn\downloads\boost_1_51_0\boost_1_51_0\boost\thread\
win32\mutex.hpp(22) : see declaration of 'boost::mutex'
1> This diagnostic occurred in the compiler generated function '
ThreadSafeClass::ThreadSafeClass(ThreadSafeClass &)'
f*******t
发帖数: 7549
44
来自主题: JobHunting版 - two functons and two threads
int i = 0;
Thread 1:
A();
i++;
Thread 2:
while(i != 1)
sleep(100);
B();
p*****2
发帖数: 21240
45
看来不能用multi thread去解题了。CF上可以起10个thread没什么问题。
s********r
发帖数: 403
46
来自主题: JobHunting版 - Code a non blocking thread safe queue
大牛不敢。
我只是写过一些简单的 non-blocking algorithm。
这些 non-blocking 算法是 Multiple-Thread Multiple Data 的编程模式,用于多核
系统,但其执行效率与体系结构,尤其是 cache 结构相关。还牵涉到 memory
consistent model。在c++11 中,很多 atomic operation 是为这个准备的。
下面的 code 仅仅代表一个思路上的描述:
void enq(Node *queue, T val)
{
Node * node = new node(val);
node->next = NULL;
Node * tail = NULL, *last = NULL;
for (;;)
{
tail = queue->gettail(); //atomic get
last = tail->next;
if (tail == queue->gettail()) //Are we still there?
{... 阅读全帖
s********u
发帖数: 1109
47
来自主题: JobHunting版 - 请问C++ threading w/ lock free algorithms
c++里的mutex,和java里的lock主要是什么区别呢?好像是说mutex是system wise的?
还有就是mutex有没有thread ownership这种概念,就是一个thread的mutex不能由另一
个来unlock。
b****z
发帖数: 176
48
leetcode的一道题目,树的中序遍历,用普通的方法可以跑过。
但是网上看到有人用Threaded Binary Tree 。感觉这已经比较难了,像这样的问题
Threaded Binary Tree , 在准备interview的时候需要掌握吗? 会不会超过难度?
M********u
发帖数: 42
49
来自主题: JobHunting版 - c++ thread 求助 (转载)
假定输入是50m,每行4个数字,sizeof(double) * 4 =~ 32 bytes, 如果全部cache在
内存里,大概需要50m * 32 =~ 2GB。有的thread finish的比较早,有的比较晚是因为
每个thread分配到一样多的count,但是有的输入可能需要算很久。这类科学计算的问
题一般使用openmp,非常容易写。
http://en.wikipedia.org/wiki/OpenMP
可以用scheduling clause里的dynamic
首页 上页 1 2 3 4 5 6 7 8 9 10 下页 末页 (共10页)