由买买提看人间百态

topics

全部话题 - 话题: threaded
首页 上页 1 2 3 4 5 6 7 8 9 10 下页 末页 (共10页)
l*m
发帖数: 824
1

if you use multiThread, you can do a public counter=0. for
every thread, which you want to monitor, you counter++ when
you start that thread, and counter-- when you quit that
thread.
and your exit thread just check the counter, if it is 0
you can quit, if it is greater than 0 you can sleep some
time and check again.
g****n
发帖数: 18
2
Hello everyone,
I am new to Java and have to ask a simple question.
I am writing a program that has two sockets s1 and s2.
s1 listens to a single client and uses a single thread
s2 listens to possible multiple clients and uses a multithread to track number
of connections, by group.activeCount();
It requires both the single thread and multithread run at the same time. And
the multithread's group.activeCount() needs to be passed to the single thread
every time a thread in the multithread starts or
h*********o
发帖数: 62
3
the thread's run method may need some local variables. Also java thread
finally will map to OS thread. each thread will have its own stack even you
have no local variables in run method. in this way, context switch is
possible.
s***s
发帖数: 104
4
来自主题: Java版 - Thread对应的input和output问题
我有一个简单的没有界面程序,在main中启动了另外一个thread。但是这两个threads都
要不同的输入和输出。现在的问题是,他们都用同一个窗口的system.in和system.out。
这样就全乱了。我想能不能给这个新的thread也开个新的console,这样分开读和写的话
就不会乱了。请问我该怎么做。或者不新开一个窗口,怎么样才能使输入和输出都分别
对应不同的threads。
谢谢!不知道表达清楚了没有。
s********r
发帖数: 176
5
I am fixing a bug in a project. The existing way to handle the case is
described as below.
There are 2 threads, one uploads(ftp) an image to the file server, the other
thread persist other relative data into the database.
Bug: if ftp image process fails, the new data still is stored into the db,
or if the data is rolled back, the image is still transferred to the file
server.
It is obvious not correct, either of them fails, all fails.
Difficulty: since here are using 2 threads, each is responsib... 阅读全帖
d**k
发帖数: 1223
6
来自主题: Java版 - 问个关于thread的问题
这几天看到大家在讨论thread的问题,突然想起来我好像很少用到thread.....上学的
时候就学的不是很清楚,后来做的project多数都是在各种framework下面的web app,似
乎没有任何chance用到thread....请教一下大家现如今都是什么情况下编程会用到
thread?谢谢先
l******n
发帖数: 577
7
如果我有一段关于synchronized的代码,比如:
Class A {
private double number = 0;
public synchronized void setNumber(value) (
this.number = value;
}
public synchronized double getNumber() {
return this.number;
}
}
这个时候,我没有对number用volatile的modifier,是不是会出现visibility的问题。
这里不会有两个tread同时setNumber,而且number我给了private,不会被class外面直
接修改。但是如果某个thread call setNumber修改了这个double的值,这里修改后的
number能不能被所有的thread看到?
或者我换个问法,假如某个thread用了setNumber(4), 结束之后另一个thread马上
调用getNumber(),返回的值,会不会一定是4?
在这种... 阅读全帖
l******n
发帖数: 577
8
我也觉得是有问题,但是这和我从书上看来的矛盾:
Locking is not just about mutual exclusion; it is also about memory
visibility. To ensure that all threads see the most up to date values of
shared mutable variables, the reading and writing threads must synchronize
on a common lock.
这个意思我的理解就是synchronized可以保证visibility to all threads,但是这段
代码如果有问题,就跟这个意思矛盾。
synchronized可以确保两个thread不会call一个method,但是synchronized对于
visibility到底有没有作用?

use
w**z
发帖数: 8232
9
According the JSR-133, the code should work.
But there is more to synchronization than mutual exclusion. Synchronization
ensures that memory writes by a thread before or during a synchronized block
are made visible in a predictable manner to other threads which synchronize
on the same monitor. After we exit a synchronized block, we release the
monitor, which has the effect of flushing the cache to main memory, so that
writes made by this thread can be visible to other threads. Before we can
ente... 阅读全帖
S*A
发帖数: 7142
10
来自主题: Linux版 - Process and Thread

Define "within".
The thread shared signal and virtual memory with the process,
does it count as "within"?
The thread is a schedule-able task just like process in Linux.
The only different with process is that it share signal and memory.
Kernel level.
No, that is not how it works now. User level threads are nightmares
when you deal with file io and sockets.
You can read a little bit more about the linux "clone" system call.
As far as I can tell, clone can be used to implement POSIX compatible
th... 阅读全帖
l******9
发帖数: 579
11
Hi,
I am trying to do parallelization for a computing intensive problem.
I am working on a Linux cluster where each node is a multicore processor.
e.g. 2 or 4 quad-core processor per node.
I want to reduce latency and improve performance as much as possible.
I plan to use multiprocessing and multithreading at the same.
Each process run on a distinct node and each process spawn many threads
on each node. This is a 2 level parallelism.
For multiprocessing, I would like to choose MPI.
For multithre... 阅读全帖
m*****r
发帖数: 130
12
来自主题: Programming版 - C# thread
你这个messup是完全正常的行为。那个Thread.sleep就是把当前thread,也就是GUI的
thread给停住,没办法画GUI了。你要想干别的,得弄个新的Thread。

time,
to
b*********n
发帖数: 1258
13
【 以下文字转载自 Java 讨论区 】
发信人: babyfacenan (黑土), 信区: Java
标 题: 急问:怎么kill一个thread, thread.interrupte()不好用呀?
发信站: BBS 未名空间站 (Sun Apr 27 15:47:01 2008)
我在MainThread里同时start了两个thread: thread1, thread2
MainThread里等了2sec之后,想要kill thread2
thread2是去obtain一个url 的content,
一般情况thread2在2-3secs之后就return url content,但有时会take up to 10 sec
想要实现在2sec之后,
如果thread2没结束就强行结束,并返回nothing,
如果thread2结束了就返回url content.
用了:thread2.interrupt() 来强行结束thread2;
但是好像没有用呀,thread2还是在运行,并没有end
而且在我连续调用MainThread时,下一次的MainThread返回的url
r******9
发帖数: 129
14
来自主题: Programming版 - boost.thread 问题
下面代码,运行没有问题
void worker()
{
cout << "worker" << endl;
}
int main()
{
boost::thread thrd1(worker);
thread.join();
}
如果换成下面这样
int main()
{
cWorker* w = new cWorker();
boost::thread thrd1(w->worer);
thrd1.join();
}
另有一个 cWorker class的定义
就编译不过,找到不matching的 boost::thread ( type>)
请教这种情况应该怎么调用 worker呢?
谢谢
n********y
发帖数: 48
15
来自主题: Programming版 - multithread: how to lock a thread
程序的基本结构如下所示,
class priceserv{
public:
priceserv(){
}
virtual ~priceserv(){
}
int run()
{
// connect to the price server
// waiting for the price events, and call the corresponding
callback function.
}
//callback function
bool on_quote(char *data)
{
//printf data
}
bool on_trade(char *data)
{
//printf data
}
bool on_depth(c... 阅读全帖
l******9
发帖数: 579
16
Hi,
I am trying to do parallelization for a computing intensive problem.
I am working on a Linux cluster where each node is a multicore processor.
e.g. 2 or 4 quad-core processor per node.
I want to reduce latency and improve performance as much as possible.
I plan to use multiprocessing and multithreading at the same.
Each process run on a distinct node and each process spawn many threads
on each node. This is a 2 level parallelism.
For multiprocessing, I would like to choose MPI.
For multithre... 阅读全帖
z****e
发帖数: 54598
17
来自主题: Programming版 - wdong你可以把event和thread拆开来
你敲了那么多为啥删了?
我就是这么做的
建模还是需要thread(vert.x的worker)
但是接收命令,用event(vert.x的一般verticle)
回合制游戏本身不就是一个接收命令
然后启动thread去轮询的一个过程吗?
哪怕是在客户端都是这样写的
我重用了客户端的model代码
客户端用mvc,服务器端用vert.x来接受命令
然后寄存到map里面去,命令本身是immutable的
然后每一局启动一个thread,当然这个thread已经建好模了
然后轮训map,然后执行命令后广播出去
c*********e
发帖数: 16335
18
Apache is a multi-threaded HTTP server。 但是,据说要真正的multi-thread,比如
要开5个thread,就要有5个cpu. 是这样的吗?
k**********g
发帖数: 989
19
来自主题: Programming版 - malloc per-thread arena

http://stackoverflow.com/questions/855763/is-malloc-thread-safe
Mostly related to the NO_THREADS define. It could be a hassle to search for
defines in large libraries especially when there are dependencies on third-
party libraries.
Microsoft MSVCRT also has "single threaded version" and "multi-threaded
version".
Basically, there's no reason to use the single-threaded version C runtime
nowadays.
c*********e
发帖数: 16335
20
python + django可以作multi-threading,php multi-threading貌似没python的好啊。
哪位大虾比较一下python, php在multi-threading的区别?
github就是用python + django 作的。
l******9
发帖数: 579
21
Hi,
I am trying to do parallelization for a computing intensive problem.
I am working on a Linux cluster where each node is a multicore processor.
e.g. 2 or 4 quad-core processor per node.
I want to reduce latency and improve performance as much as possible.
I plan to use multiprocessing and multithreading at the same.
Each process run on a distinct node and each process spawn many threads
on each node. This is a 2 level parallelism.
For multiprocessing, I would like to choose MPI.
For multithre... 阅读全帖
w**n
发帖数: 88
22
来自主题: Unix版 - Does Linux support thread?
There are 2 levels of thread: kernel level and user level thread, The first
one needs kernel support , the latter one handled by the libary, and kernel
doesnt know anything about multi-thread in a process, that is the way how
Java works.
Programming lang only support multi-thread in user-level, multi-process
must be supported by kernel
l******9
发帖数: 579
23
Hi,
I am trying to do parallelization for a computing intensive problem.
I am working on a Linux cluster where each node is a multicore processor.
e.g. 2 or 4 quad-core processor per node.
I want to reduce latency and improve performance as much as possible.
I plan to use multiprocessing and multithreading at the same.
Each process run on a distinct node and each process spawn many threads
on each node. This is a 2 level parallelism.
For multiprocessing, I would like to choose MPI.
For multithre... 阅读全帖
m*****g
发帖数: 54
24
来自主题: _Python版 - can not start thread
If you really really need that many threads, you need use 64 bit OS.
That said, using thread is not free, It is crazy for one process to try to
create more than 300 threads. using
thread pool sound like a better approach
r********n
发帖数: 7441
25
来自主题: Military版 - c++ thread 求助 (转载)
每个thread应该锁定一个block来处理,否则效率太低
36个thread根本没必要,4-8个就足够用了

thread
h******k
发帖数: 13418
26
来自主题: Military版 - c++ thread 求助 (转载)
需要两个buffer,一个io thread,总thread不超过总vcpu,thread全部bind
R***r
发帖数: 120
27
来自主题: JobHunting版 - 一个thread如何kill另外一个thread?
我听说good practice应该是设一个share variable as flag,当要kill这个thread的
时候就set the flag,然后让这个thread terminate itself。
r*********s
发帖数: 2157
28
来自主题: JobHunting版 - multi thread复习请教
我觉得multi thread的面试有点特别
电话面试不会有什么花样, 无非是几个概念 process/thread, deadlock, mutex/
semaphore, communication 等等
onsite如果碰到multi thread就比较麻烦, 如果你以前没有自己做过, 只是看了些书,
当场很容易stuck在那里.
o*****e
发帖数: 99
29
来自主题: JobHunting版 - 一道关于SMP and threading 题目
What's the potential problem in the following code if the code is executed
on a SMP machine.
int counter[2]; /* global variable */
/* thread 0 */
counter[0] = 0;
for (i = 0; i < 500000; i++)
counter[0] += counter[0] * 2;
counter[0] /= 2;
}
/* thread 1 */
counter[1] = 0;
for (i = 0; i < 500000; i++)
counter[1] += counter[1] * 2;
counter[1] /= 2;
}
Threading
M*******a
发帖数: 1633
30
来自主题: JobHunting版 - n thread rendezvous怎么做用semaphore
两个thread这样:
thread a
1 statement a1
2 aArrived.signal()
3 bArrived.wait()
4 statement a2
thread b
1 statement b1
2 bArrived.signal()
3 aArrived.wait()
4 statement b2
h**********c
发帖数: 4120
31
NOP, lobj is always thread local, lock its instantiation thread.
this is threads shared.
if you draw a dependency graph, it is SIMPLE to show!
public void addA() {
Object lobj = new Object();
syncronized (lobj) {
a++;
}
}
c*******a
发帖数: 1879
32
【 以下文字转载自 Programming 讨论区 】
发信人: centralla (central LA), 信区: Programming
标 题: linux下, 一个thread 正在写文件,如果另一个thread试图去删去这个文件
发信站: BBS 未名空间站 (Mon Oct 2 19:52:10 2017, 美东)
会不会产生deadlock?
y*d
发帖数: 2226
33
Windows会,linux不会
windows里文件会被锁住
linux里只是删了目录结构里的引用,写thread里的引用还在。等写thread关了文件,
才会被垃圾回收。
这个垃圾回收比JAVA里的简单很多,只要引用计数就行了
P***e
发帖数: 804
34
Not sure if someone has ever posted this from FW:
______________________________________________________
An Amex Cash Rebate Card FAQ and Strategy Thread
This is thread for discussing the new Amex Cash Rebate Card. I and no doubt
others have received several PMs asking about how this crazy beast works, and
several of us are very interested in figuring out how to best use it. I’m
hoping that this thread will both clarify the card’s functioning AND help us
maximize its potential.
This card replace
G***G
发帖数: 16778
35
来自主题: Fishing版 - thread, core, processor
suppose we have one processor with one core.
suppose, when traditionaly we download a file from internet with one thread,
it would take 10 minutes.
if we use multi-threads software to download it (suppose 10 threads),
do you feel it would decrease the downloading time amazingly,
or they cost just the same time (both are 10 minutes because your computer
are one cpu with one core?
t*******y
发帖数: 10477
36
来自主题: Fishing版 - thread, core, processor
Dude, this has nothing to do with how many cores does a CPU has.
Multi threading will definitely decrease the time of downloading. Try
flashget and you
will see the difference.
The magic is, CPU is much faster than IO. Your PC may have only one CPU with
one core,
but think about how many things it is running simultaneously: windows, mouse
,
keyboard, service, networking, disk management...the CPU switch between
these tasks
thousands of times each second.
Thus, when you use multiple threads to do... 阅读全帖
k****e
发帖数: 297
37
来自主题: Fishing版 - thread, core, processor
It partially depends on the server where the file stored and your connection
bandwidth.
In the case the server has limit on download speed per thread but allow
multiple request, and your bandwidth happened to be more than that limit,
the multi-threads
could do decrease the downloading duration.

thread,
wh
发帖数: 141625
38
来自主题: Translation版 - 湘绣:Loose Threads, Rich Colors
今天翻译的文章里有这么一句话,说湘绣的特色是“loose threads and rich colors
”。我起先翻译成“针脚疏松,色彩鲜明”。但“针脚疏松”听着像是贬义似的。查维
基、百度的湘绣词条,都是说针脚严密、整齐,没有说疏松的。在百度词条里找到一句
“线条洒脱”,我如获至宝地拿来用了,想来应该是这个意思?如果是的话,这个
loose threads的英译可实在不确切,要是我就翻成free threads...哈哈。
顺便贴几个线条洒脱、色彩鲜明的湘绣,你们最喜欢哪一幅?祝版友们节日快乐!
(该绣屏为孙中山先生与宋庆龄结婚时陈列的湘绣花鸟条屏。在仿古色的缎料上,以传
统中国工笔画的表现形式,分别做紫藤、牡丹、菊花、梅花并配题诗相映衬,具有传统
文人画的思想内涵。每幅均有比翼双飞的双鸟,象征同心和谐的报喜气氛。绣品均采用
平针和掺针绣法,设线朴实平和,使条屏显得十分精致高雅。是一套传统湘绣的经典作
品。)
l*****s
发帖数: 52
39
请教各位大侠:各位听说过自动保存news group
Thread的软件吗?老板正在做一个project,要分析news group的有关某个topic的谈话。
问题是我找不到一个方法能自动把news group的Thread自动存成文件的工具或编程界面。
我曾经想用Google API service,不过后来发现它还很不完善,不支持对news group的网
页保存,只支持indexed web pages。不知道各位是否听说过有类似的软件工具或编程界
面,假设我已经知道news group的URL,希望保存所有的thread。
先多谢了!
k****i
发帖数: 1072
40
来自主题: DotNet版 - .Net Thread question
How do you know that other threads is not moving on?Do you really start the
threads before the main thread goes to sleep?

to
a******e
发帖数: 15
41
来自主题: DotNet版 - Thread suspend and resume

Yeah I have read that article. The problem is that I cannot find a good
alternative for Thread.Suspend and Thread.Resume. For example, if I have a
worker thread which does sth taking a long time (a process which is not a
loop) and the user would like to have the option to suspend and resume the
process, what is the best way to do this in .Net?
Any suggestion?
Thanks.
if
System.Console.WriteLine,
l******9
发帖数: 579
42
In MPI libraries with shared memory implemented, we have inter-process
communication or inter-thread communication ?
If it is former, why process has less overhead than thread ?
If it is later, why it has less overhead than openMP and threading?
Does MPI has some built-in advantages over them ?
Any help is really appreciated.
Thanks
l********d
发帖数: 1590
43
来自主题: Java版 - Re: native thread 和green thread
Native Thread 由kernal 来实现,开销最小,green thread由用户进程来实现,与
Kernal 无关,
g****y
发帖数: 323
44
Like event-handling code, painting code executes on the
event-dispatching thread. While an event is being handled,
no painting will occur. Similarly, if a painting operation
takes a long time, no events will be handled during that
time.
因此,比如在某个ActionListener里呼叫repaint()是的不到好结果
的,因为同为awt-event-queue Thread, 你的repaint()的不到正确
的执行,尤其是如果在一个loop里呼叫repaint(), 估计只有最后一
个repaint()在ActionListener被执行完后执行。解决的办法只有将
对repaint()的呼叫放在另外一个Thread上,再actionPerform()里呼
叫该方法,这样ActionListener可以很快的执行完,释放awt-event-
queue
g****y
发帖数: 323
45
来自主题: Java版 - FrameWork of Thread application 1
This FrameWork will be used if you have
1.your own GUI updated part, not calling repaint().
2.Tough work, like lots of calculations
3.You want to be able to stop the thread.
Thread workHarder = new Thread() {
public void run() {
doTougherWork();
SwingUtilities.invokeLater( new Runnable () {
public void run() {
updateMyComponents(); // update the state of
component(s)
}
});
}
};
workHarder.start();
public void doT
E*****l
发帖数: 2662
46

Usually what you should do for situation like this is to
design a class with mutually exclusive functions (use
synchronized prefix). All the file access should be implemented
in this class. In this way when a thread is doing something
to the file, no other thread can access the file. This may
not be what you want if you want to allow multiple threads
to read the file at the same time though. You can follow
the logic and design a class which allows multiple reads but
no read when writing is goin
g****n
发帖数: 18
47
I wrote a server. It has a threadGroup (threadPool) keeping track of number of
threads connecting to port 5012, using group.activeCount().
The server also has another port 6012 open and uses it to communicate with a
dispatcher. This is a single thread setup. Is there a way to pass the value
group.activeCount to the thread on port 1235? I tried, but the value is not
updated everytime a client is connected to the server. I am attaching the code
as follows. Can anyone point out where something is w
b*********y
发帖数: 7
48
You should use a flag, say, boolean stopThread = false, it's shared by both
main thread and thread2; thread2 keep polling it in its run() method,once
the flag's status changes, thread2 exits run() and terminates itself.
MainThread is to toggle the flag after 2 seconds.
However, execise with great caution, the toggling and checking the status of
the flag, is to be guarded by synchronization to ensure the mutual
exclusion and inter-thread communication.
Please refer to "Effective Java" 2nd edition
m******t
发帖数: 2416
49
If thread2 is stuck in native socket code -- e.g.
trying to connect to the url, there is no (java)
way to interrupt it. The only possibility AFAICS
would be to start it as a daemon thread.
I hope everybody realizes that this was a thread
from over a year ago, by the way. 8-)
l*****b
发帖数: 82
50
Thanks, goodbug. Those are good advice. I have some questions on them:
For logger per thread, will it impact the performance? Provided thread pool
max is 200, there are about 200 logger at some time.
For customed SMTPAppender, how many buffer should I set? If threads
increased, it has chance the fixed buffer cannot reach the first log entry.
首页 上页 1 2 3 4 5 6 7 8 9 10 下页 末页 (共10页)