|
From: Scott H. <he...@di...> - 2003-07-24 15:45:40
|
Hello,
With valgrind-20030716 I'm once again happily checking my apache modules
on a RedHat 8+patches box using glibc-2.3.2. Except, one module that uses
flock() to synchronize on access of a file. When running with valgrind it
hangs on the second call to flock when the file is locked. Is this
expected?
When testing I just turn off the flock code since it is only hit on rare
occasions so it's not too big of a problem. I've got a bit of sample code
below. It runs fine alone but hangs on the second call to flock().
Thanks,
Scott
#include <pthread.h>
#include <iostream>
// These are all used for saving sessions to disk
#include <cstdlib> // malloc
#include <sys/file.h> // file locking
#include <unistd.h> // close()
using namespace std;
class thread
{
public:
static void thread_func( int* arg ) {
int fileDesc = open( "./spam", O_RDWR|O_CREAT, 0666 );
if ( fileDesc < 0 )
cerr << "Failed to open file. " << strerror( errno ) << endl;
cerr << "Starting to lock: " << *arg << endl;
int locked = flock( fileDesc, LOCK_EX );
if ( locked != 0 )
cerr << "Failed to lock file. " << strerror( errno ) << endl;
cerr << "Starting to sleep: " << *arg << endl;
// Make it leak
malloc( 8 );
sleep( *arg );
cerr << "Done sleeping: " << *arg << endl;
close( fileDesc );
cerr << "Done locking: " << *arg << endl;
}
};
int main( int argc, char* argv[] )
{
pthread_t tid1, tid2;
int p, q;
p = 3;
pthread_create( &tid1, NULL,
(void *(*)(void*)) thread::thread_func,
&p );
q = 2;
pthread_create( &tid2, NULL,
(void *(*)(void*)) thread::thread_func,
&q );
pthread_join( tid1, NULL );
pthread_join( tid2, NULL );
exit( 0 );
}
|