Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.os.linux.development.apps > #563
| From | ephlodur <ephlodur@linuxmail.org> |
|---|---|
| Subject | Re: pthred_con_timewait problem |
| Newsgroups | comp.os.linux.development.apps |
| References | <InRNs.867$OE1.126@newsfe26.iad> <87pq0o10fw.fsf@sapphire.mobileactivedefense.com> <TURNs.86317$LS5.79873@newsfe10.iad> <ke8ri9$9g0$1@speranza.aioe.org> |
| Message-ID | <VGTNs.102542$Sl.64666@newsfe27.iad> (permalink) |
| Date | 2013-01-29 17:30 +0000 |
On Tue, 29 Jan 2013 19:58:03 +0400, Sergei Organov wrote:
> ephlodur <ephlodur@linuxmail.org> writes:
>
>> On Tue, 29 Jan 2013 15:19:31 +0000, Rainer Weikusat wrote:
>>
>>> ephlodur <ephlodur@linuxmail.org> writes:
>>>
>>> [...]
>>>
>>>> _ret = pthread_cond_timedwait(&_event_id, &_m_mutex, &ts);
>>>> unlock();
>>>>
>>>> but when ever I make that call it always return with EPERM
>>>
>>> According to the UNIX(*) standard,
>>>
>>> [EPERM]
>>> The mutex type is PTHREAD_MUTEX_ERRORCHECK or the mutex
>> is a robust
>>> mutex, and the current thread does not own the mutex.
>>>
>>> This would mean that the thread invoking pthread_cond_timedwait didn't
>>> lock the _m_mutex mutex.
>>
>> As show in my code snippet below from my class CEvent the thread is
>> locl before the call...
>> lock();//lock in this case is define as a base _ret =
>> pthread_cond_timedwait(&_event_id, &_m_mutex, &ts); unlock();
>
> When you ask for help, it's a good idea to provide minimal example that
> anyone here can compile and run to reproduce the problem.
>
> When you prepare one, you will probably see what's wrong yourself and
> won't need to ask anybody ;-)
>
> -- Sergei.
ok here is the code that I'm using but I cannot see the error in
it ..thank for any help..
the base class for my event
class Lock
{
private:
int _ret;
protected:
pthread_mutex_t _m_mutex;
pthread_mutexattr_t _attr;
// Prevent copying or assignment
Lock(const Lock& _arg);
Lock& operator=(const Lock& _rhs);
public:
Lock(){
_ret = pthread_mutexattr_init(&_attr);
_ret = pthread_mutexattr_settype
(&_attr, PTHREAD_MUTEX_NORMAL);
_ret = pthread_mutex_init
(&_m_mutex,&_attr);
if(_ret != 0) throw "Error";
}
~Lock(){
pthread_mutex_destroy(&_m_mutex);
pthread_mutexattr_destroy(&_attr);
}
int lock(){
_ret = pthread_mutex_lock(&_m_mutex);
return _ret;
}
int unlock(){
_ret = pthread_mutex_unlock(&_m_mutex);
return _ret;
}
};
below is my event class..
class CEvent : public Lock
{
private:
struct timespec _ts;
struct timeval _tp;
int _ret;
protected:
pthread_cond_t _event_id;
pthread_condattr_t cattr;
// Prevent copying or assignment
CEvent(const CEvent& _arg);
CEvent& operator=(const CEvent& _rhs);
public:
CEvent(){
pthread_condattr_init(&cattr);
_ret = pthread_condattr_setclock(&cattr,
CLOCK_MONOTONIC);
pthread_cond_init(&_event_id,&cattr);
}
~CEvent(){
pthread_condattr_destroy(&cattr);
pthread_cond_destroy(&_event_id);
}
int wait(){
lock();
_ret = pthread_cond_wait(&_event_id, &_m_mutex);
unlock();
return _ret;
}
int wait_timeout(int delay)
{
struct timespec ts;
clock_gettime(CLOCK_MONOTONIC,&ts);
ts.tv_sec += delay;
lock();
_ret = pthread_cond_timedwait(&_event_id, &_m_mutex, &ts);
unlock();
return _ret;
}
int notify(){
_ret = pthread_cond_signal(&_event_id);
return _ret;
}
};
this is my msg queue..
struct gLog_queue
{
public:
void addMsg(LOGMSG *msg) {
_result = _m_Event.lock();
_queue.push_back(_msg);
_result = _m_Event.notify();
_result = _m_Event.unlock();
}
LOGMSG *getMsg() {
_msg = NULL;
_result = _m_Event.lock();
if(_queue.size() != 0)
{
_msg = _queue.front();
_queue.pop_front();
}
_result = _m_Event.unlock();
return _msg;
}
int wait_for_msg_time(int delay){return _result =
_m_Event.wait_timeout(delay);}
int wait_for_msg(){return _result = _m_Event.wait();}
int getResult(){return _result;}
private:
CEvent _m_Event;
unsigned int _count;
pthread_t _thread_id;
std::list<LOGMSG* > _queue;
int _result;
LOGMSG* _msg;
};
this is the definition for the log queue
extern struct gLog_queue app_log_queue;
and this is my call that return EPERM..
ret = app_log_queue.wait_for_msg_time(delay);
Ps: the wait for message work wait_for_msg_time() it he
wait_for_msg_time_time() does not work..
Thanks again for any help
ephlodur.
Back to comp.os.linux.development.apps | Previous | Next — Previous in thread | Next in thread | Find similar
pthred_con_timewait problem ephlodur <ephlodur@linuxmail.org> - 2013-01-29 14:53 +0000
Re: pthred_con_timewait problem Rainer Weikusat <rweikusat@mssgmbh.com> - 2013-01-29 15:19 +0000
Re: pthred_con_timewait problem ephlodur <ephlodur@linuxmail.org> - 2013-01-29 15:28 +0000
Re: pthred_con_timewait problem Sergei Organov <osv@javad.com> - 2013-01-29 19:58 +0400
Re: pthred_con_timewait problem ephlodur <ephlodur@linuxmail.org> - 2013-01-29 17:30 +0000
Re: pthred_con_timewait problem Sergei Organov <osv@javad.com> - 2013-01-29 22:44 +0400
Re: pthred_con_timewait problem ephlodur <ephlodur@linuxmail.org> - 2013-01-30 11:28 +0000
Re: pthred_con_timewait problem Richard Kettlewell <rjk@greenend.org.uk> - 2013-01-29 16:32 +0000
csiph-web