Martin Pala <address@hidden> writes:
[clever stuff]
I tried it on simple test - in this case monit without action mutex
is less affected then monit with action mutex in check_process(),
which failes every time. To solve the race condition, it will be
needed to implement probably per-process mutex before do_validate flag
test and cervlet check_process() calls. I did it too, but i found a
deadlock in that case => it needs more work (last 'development' patch
attached -
probably there could be better way to do it).
This looks okay! The reason it does not work is that you will need to
initialize the mutex first :-) When the process is created in
p.y:createprocess() do a, pthread_mutex_init(¤t->mutex, NULL);
and likewise in gc.c:gc_process() do a
pthread_mutex_destroy(&(*p)->mutex);
but the main reason to
use a mutex is that process's start/stop methods are synchronized
(i.e. serialized) per process to avoid stuff like this:
(restart)
thread1: thread2
process.stop
is(!process.running) -> it's not running
process.start
process.start
With mutex
(restart)
thread1: thread2
LOCK
process.stop
process.start
END_LOCK
LOCK
is(!process.running) -> it's running
process.start
END_LOCK
static int do_not_validate(Process_T p) {
int rv= TRUE;
ASSERT(p);
LOCK(p->mutex)
rv= (!p->do_validate ||
check_skip(p) ||
check_timeout(p) ||
check_checksum(p));
END_LOCK;
return rv;
}