由买买提看人间百态

topics

全部话题 - 话题: pthreads
首页 上页 1 2 3 4 5 6 7 8 下页 末页 (共8页)
b***n
发帖数: 462
1
没用过这个,不是很懂,有问题:
f2中应该锁t2_mutex 吧。
f1中 t1_ready = 1 在 if (1==t1_ready) 后面能行吗?这个没看明白。这样的会少一次的变量传递吧。
学习了。
d****f
发帖数: 313
2

只有锁同一个mutex,才有互斥的可能啊,锁了两个mutex就毫无意义了
一次的变量传递吧。
t1_ready=1表示t1的工作做完了,做完之后要用该标志量,解锁t2线程,如果不用标志量,
可能导致condion signal丢失的
b***n
发帖数: 462
3
t2_mutex 是我想岔了。
f1中 t1_ready = 1 在 if (1==t1_ready) 后面能,也就是说,每两次 (0==(it1 % N
))才能又一次进入 if (1==t1_ready),让thread sleep。不知道这个是不是你要求的。
当f2加入进来,每一个循环都t1_ready=0, 那么,f1可能永远也没有机会进入sleep。
不知掉这样的话他们交换的数据是否是相同步骤的。
当临界情况发生的时候,能满足你的需求吗?
而且,会不会两个同时sleep?这个我还没想好。
不过学习了一下pthread_cond_wait,很有意思的一个东西。
b***n
发帖数: 462
4
还有一个,看手册,pthread_cond_wait最好使用while等待,因为有suprise wakeup的可能,这样就需要再次进入sleep。你的if 等待被suprise wakeup后会进入下一轮计算,这样的话是不是就不是你要得结果了?
所以最好是两个thread有各自的if condition。
现学现卖,一起讨论吧。
b***n
发帖数: 462
5
总觉得你这个需要步调一致,对数据的互斥反而可以通过步调控制。不知道是不是这样
h***i
发帖数: 1970
6
哪那么容易,看代码复杂程度,两个系统不一样的东西太多了,随便举例,windows没
fork,没pthread(这个倒是可以找个open source的),很多posix的东西windows都没有
,你以为为了支持多系统的程序,那些ifdef是写着玩的? 计算机系能都搞定的都不多。
d**d
发帖数: 389
7
【 以下文字转载自 Programming 讨论区 】
发信人: dxxd (东邪西毒), 信区: Programming
标 题: 请教一个linux下的POSIX timer的问题。
发信站: BBS 未名空间站 (Fri May 13 17:06:15 2011, 美东)
我用linux下面的POSIX timer, timer_create(),timer_settime(),
为什么在调用了timer_settime()以后,立马就有一个time-out callback? 然后再每过
5秒后有一个time out?
难道不是我调用timer_settime()以后,timer开始计时, 等到5秒以后再出现第一
time out callback 吗?
非常感谢!
代码如下:
#include
#include
#include
#include
#include
void
handle (sigval_t v)
{
tim... 阅读全帖
G*****7
发帖数: 1759
8
cuda and be done with all the mess.
s******s
发帖数: 505
9

Intel TBB
G*****7
发帖数: 1759
l*****o
发帖数: 473
11
It didn't make sense at all to create many threads for computation intensive
tasks.
If you want to hide IO latency, then you maybe need it. Otherwise, there is
no use at all. BTW, switching between threads is light weight, but still you
need to pay overhead.
j******o
发帖数: 82
12
来自主题: Programming版 - Windows Thread API
想自己写一个简单的Thread Pool.用过PThread和Java的Thread,看了一下MSDN的
Windows
Thread API,但好像都是C Function不知道有没有C++的Class?请指点一下,给各LINK之
类.
谢谢!
l*****n
发帖数: 633
13
【 以下文字转载自 Linux 讨论区 】
发信人: luxilon (昵称不好起), 信区: Linux
标 题: 请帮忙看个thread的问题 (with memory dump)
发信站: BBS 未名空间站 (Mon Mar 5 18:26:04 2007), 转信
试着编了一个程序,有10多个pthreads同时运行,出现下面的错误,读不太懂,请帮忙
分析一下memory(stack, heap)。是不是分配给给个thread的stack太少了。该怎样调整?
thanks.
s******y
发帖数: 68
14
来自主题: Programming版 - 这是怎么回事?
在UNIX下GCC编译C程序fork.c生成a.out, 大多数时候正常工作.
但个别时候, 出现如下异常情况. 什么原因. 谢谢
$ gcc fork.c -o a.out -pthread
$ ./a.out
./a.out
c*****e
发帖数: 34
15
来自主题: Programming版 - 关于valgrind 的一个问题
对,用了pthread. 跟这个有关系吗?
f******n
发帖数: 90
16
来自主题: Programming版 - 学习multi threading, 有什么好书?
what about this one?
Pthreads Programming: A POSIX Standard for Better Multiprocessing (O'Reilly
Nutshell)
O*******d
发帖数: 20343
17
来自主题: Programming版 - 学习multi threading, 有什么好书?
那本书还可以. 有些基本概念没讲.
Pthread可以在windows上用. 如果要用native, 可看这本书
Win32 Multithreaded Programming
w***n
发帖数: 1137
18
来自主题: Programming版 - 问一个c的问题
看到一个程序, 里面有这么一句。
#include
#include
#include "errors.h"
typedef struct alarm_tag {
struct alarm_tag *link;
int seconds;
time_t time; /* seconds from EPOCH */
char message[64];
} alarm_t;
在主程序力有这么一句
alarm->time = time (NULL) + alarm->seconds;
以前没有见过这种用法,这句到底是什么意思?
s***e
发帖数: 793
j********e
发帖数: 240
20
来自主题: Programming版 - EBUSY 的定义
这个 pthread_mutex_trylock() 返回值的定义在哪儿?
在#include 没有啊?
b********n
发帖数: 609
21
来自主题: Programming版 - 有啥比较好的multithreaded C++ project?
用pthread编的,在Linux上run的,open source的好像非常少啊。
j****g
发帖数: 597
22
来自主题: Programming版 - 要写一个user level thread library
something about pthread.
My OS homework. hehe.
p***o
发帖数: 1252
23
来自主题: Programming版 - pthread and C++
Why not?
D*******a
发帖数: 3688
24
来自主题: Programming版 - pthread and C++
right, use a small C function to serve as a thread stub
p***o
发帖数: 1252
25
来自主题: Programming版 - pthread and C++

en.wikipedia.org/wiki/Zthread
f******e
发帖数: 164
26
【 以下文字转载自 Linux 讨论区 】
发信人: francise (小飞猫), 信区: Linux
标 题: Linux thread和NPTL thread什么关系?
发信站: BBS 未名空间站 (Wed Mar 26 17:31:38 2008)
请问Linux thread和NPTL thread什么关系?通常用的pthread, POSIX thread和他们又
是什么联系?谢谢
f******e
发帖数: 164
27
pthread和Linux thread没关系么?
v*****x
发帖数: 8
28
pthread_cond_wait only waits for signal happens after.
So, the correct sequence is:
thread 1 waits (suspends)
thread 2 signals
thread 1 proceeds.
In your scenario:
thread 2 signals (which makes you assume thread 1 should return immediately
from a subsequent wait)
thread 1 waits (suspends indefinitely until next time thread 2 signals)
For more information, refer to pthread reference.

)
f*******y
发帖数: 988
29
来自主题: 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++ )
b********p
发帖数: 875
30
来自主题: Programming版 - 请教c++ multithreading
从pthread学起把
P********e
发帖数: 2610
31
来自主题: Programming版 - 请教,networking高手
zthread和pthread哪个用的比较广泛一点?
都是free open library?
T*****9
发帖数: 2484
32
来自主题: Programming版 - 请教,networking高手
显然pthread
T*****9
发帖数: 2484
33
来自主题: Programming版 - 有专门介绍multithreading编程的书吗
pthread
T*****9
发帖数: 2484
34
来自主题: Programming版 - multi-thread 一问,
use lock or semaphore
可以用buffer,然后对这个buffer用2个semaphore,1个lock或者3个semaphore
你可以看看pthread,同时我觉得fifo的实现基本是1读1写(事实上是多读多写),你可
以看看他的实现
m*****e
发帖数: 4193
35
alarm
but be careful with signal handlers - they are limited in functionality.
A better way is to use select() or pthread, depending on your case.

3s
p**p
发帖数: 3386
36
正如楼上有人说的,pthread可以做到,而且精度高

3s
T*******i
发帖数: 4992
37
来自主题: Programming版 - 对pthread熟悉的XD请进来看看
loop
p**p
发帖数: 3386
38
来自主题: Programming版 - 对pthread熟悉的XD请进来看看
你是指用loop来轮询变量么?前面帖子里说了,希望尽量避免用这种方式
T*******i
发帖数: 4992
39
来自主题: Programming版 - 对pthread熟悉的XD请进来看看
put condition_wait at the beginning of the loop
X****r
发帖数: 3557
40
来自主题: Programming版 - 对pthread熟悉的XD请进来看看
再wait就是了,signal只是一次性的。
m*****e
发帖数: 4193
41
来自主题: Programming版 - 对pthread熟悉的XD请进来看看
use semophore
p**p
发帖数: 3386
42
来自主题: Programming版 - 对pthread熟悉的XD请进来看看
原来如此,多谢指点!!!
T*******i
发帖数: 4992
43
来自主题: Programming版 - 对pthread熟悉的XD请进来看看
郁闷呀
这个版每次答完问题,都是把我晾一边
p****s
发帖数: 32405
44
来自主题: Programming版 - 对pthread熟悉的XD请进来看看
我来代谢一次.
//hand hand, 昨天你回答的getopts我后来也看到了.
X****r
发帖数: 3557
45
来自主题: Programming版 - 对pthread熟悉的XD请进来看看
人不知而不愠,不亦君子乎。
T*******i
发帖数: 4992
46
programming with pthread
r****q
发帖数: 356
47
来自主题: Programming版 - how to debug multi-thread program?
I am using pthread, how do not know how to debug the program when there is
deadlocks and how to know the program is in deadlock?
m*****e
发帖数: 4193
48
来自主题: Programming版 - 关于thread的stack
The description is not entirely accurate.
For Linux pthread/x86, each thread allocates a block of virtual memory for
its stack use. It's not the typical "stack area" in the sense of memory
management.

are
立顺序的逆序进行的。)
首页 上页 1 2 3 4 5 6 7 8 下页 末页 (共8页)