Is there a way to lock file between threads in one process?

Is there a way to lock file between threads in one process?

Post by spacele » Tue, 22 May 2001 17:33:31



Is there a way to lock file between threads in one process?

system calls like fcntl or lockf doesn't work between thread in one
process...

I think there must exist a way!!

Please, let me know the way If someone knows....

Thanks in advance
Best Regards
Space Lee

 
 
 

Is there a way to lock file between threads in one process?

Post by Mathias Waac » Tue, 22 May 2001 19:46:13



> Is there a way to lock file between threads in one process?

Are there any reason why you don't use a pthread_mutex_t (or a similar
structure for your favorite thread lib) for this purpose?

Mathias

 
 
 

Is there a way to lock file between threads in one process?

Post by spacele » Tue, 22 May 2001 21:48:42


Thanks for your interest in my question ~^^
My case is like this.

Several threads don't refer to one determined file.
Each thread refer to several files in each session and
each thread handle INDEFINITE NO of session in their life time and
there are TOO many files.

So I can't use mutex...
If there is only one or some determined files,
I can use a mutex per file after pre-determine mutex variables (such as no
of mutex variables).
But I can't ....

Is there a way adapt to my situation...?


> > Is there a way to lock file between threads in one process?

> Are there any reason why you don't use a pthread_mutex_t (or a similar
> structure for your favorite thread lib) for this purpose?

> Mathias

 
 
 

Is there a way to lock file between threads in one process?

Post by Casper H.S. Dik - Network Security Engine » Tue, 22 May 2001 22:19:45


[[ PLEASE DON'T SEND ME EMAIL COPIES OF POSTINGS ]]


>So I can't use mutex...
>If there is only one or some determined files,
>I can use a mutex per file after pre-determine mutex variables (such as no
>of mutex variables).
>But I can't ....

It's all a small matter of software engineering; you will need to
make a table of all active files and associate a mutex with each
file; once no thread references the file anymore, you free the mutex.

Casper
--
Expressed in this posting are my opinions.  They are in no way related
to opinions held by my employer, Sun Microsystems.
Statements on Sun products included here are not gospel and may
be fiction rather than truth.