boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - how to statically initialze a mutex in class?
相关主题
pthread_create inside a constructor
请教pthread producer-consumer问题
double-checked locking
is pthread_mutex_destroy() required to call?
弱问C编程一个关于static问题
C++ InitializeCriticalSection问题
static initialization dependency c++
c的小问题
c++ 不自动initialize变量么?
EBUSY 的定义
相关话题的讨论汇总
话题: mutex话题: sz话题: 0x话题: initialze话题: pthread
进入Programming版参与讨论
1 (共1页)
g*********s
发帖数: 1782
1
the following code gives me warnings. what does it mean and does it matter?
inclass_mutex.cpp: In constructor ‘X::X(unsigned int)’:
inclass_mutex.cpp:8: warning: extended initializer lists only available with
-std=c++0x or -std=gnu++0x
inclass_mutex.cpp:8: warning: extended initializer lists only available with
-std=c++0x or -std=gnu++0x
#include
class X {
public:
X(unsigned int in_sz = 0): sz (in_sz)
{
buffer = new int[sz];
lock = PTHREAD_MUTEX_INITIALIZER;
// pthread_mutex_init(&lock, NULL); // this is ok.
}
~X()
{
if ( sz != 0 ) {
delete buffer;
}
}
private:
unsigned int sz;
int* buffer;
pthread_mutex_t lock;
};
t****t
发帖数: 6806
2
that macro (PTHREAD_....blahblah) is in the form of {....}. for c++98, you
can only use it in static objects. c++0x allow you to do it for auto objects.

with
with

【在 g*********s 的大作中提到】
: the following code gives me warnings. what does it mean and does it matter?
: inclass_mutex.cpp: In constructor ‘X::X(unsigned int)’:
: inclass_mutex.cpp:8: warning: extended initializer lists only available with
: -std=c++0x or -std=gnu++0x
: inclass_mutex.cpp:8: warning: extended initializer lists only available with
: -std=c++0x or -std=gnu++0x
: #include
: class X {
: public:
: X(unsigned int in_sz = 0): sz (in_sz)

g*********s
发帖数: 1782
3
thx!

you
objects.

【在 t****t 的大作中提到】
: that macro (PTHREAD_....blahblah) is in the form of {....}. for c++98, you
: can only use it in static objects. c++0x allow you to do it for auto objects.
:
: with
: with

1 (共1页)
进入Programming版参与讨论
相关主题
EBUSY 的定义
c++问题
pthread in cygwin
waiting for N condition variables in linux
condional variable thread sync 问题 (转载)
多线程的程序设计有什么好书推荐? (转载)
question about the read/write locker
how many ways in C++ to release a mutex?
How to avoid deadlock ?
你们都检查这些system call的返回值吗?
相关话题的讨论汇总
话题: mutex话题: sz话题: 0x话题: initialze话题: pthread