由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - c++问题
相关主题
condional variable thread sync 问题 (转载)pthread in cygwin
waiting for N condition variables in linuxdouble-checked locking
pthread mutex能不能用与thread和process之间多线程的程序设计有什么好书推荐? (转载)
Pthread support on Windows XPquestion about the read/write locker
java里用synchronized包住block就可以保护多线程同步问题了,这就是c里面的mutex吧?is pthread_mutex_destroy() required to call?
Re: 别了,纽约 (转载)how to statically initialze a mutex in class?
EBUSY 的定义how many ways in C++ to release a mutex?
mutex一问How to avoid deadlock ?
相关话题的讨论汇总
话题: mutex话题: c++话题: critical话题: section话题: pthread
进入Programming版参与讨论
1 (共1页)
S**Y
发帖数: 136
1
请写一个thread-safe的class,用c++,
讲思路
我说的是写一个monitor那样的class,来保证一些methods synchronized
不知道对不对...c++又不直接提供像java那样的monitor.
q***q
发帖数: 3356
2
用一个static变量做mutex?

【在 S**Y 的大作中提到】
: 请写一个thread-safe的class,用c++,
: 讲思路
: 我说的是写一个monitor那样的class,来保证一些methods synchronized
: 不知道对不对...c++又不直接提供像java那样的monitor.

I*****y
发帖数: 602
3
主要是对所有的成员变量存取都要做lock/unlock。
1. 可以声明所有成员变量为protected or private, 然后专门写存取函数。
2. 内部函数用到的地方也需要做控制,如果允许的话,就用1的存取函数存取。如果性
能优先的话,内部函数用的地方加unlock/lock。

【在 S**Y 的大作中提到】
: 请写一个thread-safe的class,用c++,
: 讲思路
: 我说的是写一个monitor那样的class,来保证一些methods synchronized
: 不知道对不对...c++又不直接提供像java那样的monitor.

t****u
发帖数: 8614
4
1) Define a mutex.
2) for each public/protected member function, put mutex lock at beginning,
and unlock at the end.

【在 S**Y 的大作中提到】
: 请写一个thread-safe的class,用c++,
: 讲思路
: 我说的是写一个monitor那样的class,来保证一些methods synchronized
: 不知道对不对...c++又不直接提供像java那样的monitor.

P********e
发帖数: 2610
5
mutex is slow
use criticalsection

【在 t****u 的大作中提到】
: 1) Define a mutex.
: 2) for each public/protected member function, put mutex lock at beginning,
: and unlock at the end.

t****t
发帖数: 6806
6
critical section is windows only, not portable.

【在 P********e 的大作中提到】
: mutex is slow
: use criticalsection

P********e
发帖数: 2610
7
or there must be a portable kernel level something in other OS:)

【在 t****t 的大作中提到】
: critical section is windows only, not portable.
r****e
发帖数: 3
8
you can take a look at boost thread library. It may have what you want.
t****t
发帖数: 6806
9
on the contrary, pthread use mutex for critical section.

【在 P********e 的大作中提到】
: or there must be a portable kernel level something in other OS:)
p***o
发帖数: 1252
10
pthread has a spinlock. Probably you can use that to construct
something similar to critical section in Win32.

【在 t****t 的大作中提到】
: on the contrary, pthread use mutex for critical section.
t****t
发帖数: 6806
11
true, but i heard it's not support everywhere either?

【在 p***o 的大作中提到】
: pthread has a spinlock. Probably you can use that to construct
: something similar to critical section in Win32.

p***o
发帖数: 1252
12
I don't know. They are supposed to be useful for multi-core systems.
Anyway, those coarse grained locks are not good in terms of multi-core
performance.

【在 t****t 的大作中提到】
: true, but i heard it's not support everywhere either?
1 (共1页)
进入Programming版参与讨论
相关主题
How to avoid deadlock ?java里用synchronized包住block就可以保护多线程同步问题了,这就是c里面的mutex吧?
请教pthread producer-consumer问题Re: 别了,纽约 (转载)
pthread_create inside a constructorEBUSY 的定义
你们都检查这些system call的返回值吗?mutex一问
condional variable thread sync 问题 (转载)pthread in cygwin
waiting for N condition variables in linuxdouble-checked locking
pthread mutex能不能用与thread和process之间多线程的程序设计有什么好书推荐? (转载)
Pthread support on Windows XPquestion about the read/write locker
相关话题的讨论汇总
话题: mutex话题: c++话题: critical话题: section话题: pthread