由买买提看人间百态

topics

全部话题 - 话题: filelock
(共0页)
c****o
发帖数: 41
1
来自主题: JobHunting版 - 出个题
My 2 cents. 多个reader可以同时读;但假如有多个reader读时来了一个writer,则之
后的
reader不能再读,直到writer结束。
读文件:
FileLock.Readlock();
//read ...
FileLock.ReadUnlock();
写文件:
FileLock.WriteLock();
//write ...
FileLock.WriteUnlock();
class FileLock 如下:
class FileLock
{
private:
Lock m_ReadCounterLock;
Lock m_FileLock;
Lock m_writerWaitLock;
int m_ReaderCount;
public:
void ReadLock()
{
m_ReadCounterLock.lock();

// 如果有writer等,block
m_writerWaitLock.lock();
m_writerWaitLock.un... 阅读全帖
N*D
发帖数: 3641
2
来自主题: JobHunting版 - 出个题
非常接近了,不过Readlock里面对于writerWaitLock用法有些问题。lock总是为了lock
些什么东西,那个地方啥也没干,就是check一下,假设check当时没有waiting write
,check一结束就来了一个write呢?两个人就一块儿读写文件了。

My 2 cents. 多个reader可以同时读;但假如有多个reader读时来了一个writer,则之
后的
reader不能再读,直到writer结束。
读文件:
FileLock.Readlock();
//read ...
FileLock.ReadUnlock();
写文件:
FileLock.WriteLock();
//write ...
FileLock.WriteUnlock();
class FileLock 如下:
class FileLock
{
private:
Lock m_ReadCounterLock;
Lock m_FileLock;
Lock m_writerWaitLock;
int m_ReaderCount;
public:
void R... 阅读全帖
f***o
发帖数: 31
3
来自主题: BuildingWeb版 - JAVA and Web 请教
you need a web server anyway;
one file is ok. use FileLock
g**********y
发帖数: 14569
4
来自主题: Java版 - Help on file locking
Java seems have not so perfect FileLock mechanism --
1. lock() will physically lock the file in that OS. The second call lock()
will cause Exception thrown. Ideally, if the second call comes from the same
thread, it should be fine. However, JVM failed here.
I write a piece of code:
RandomAccessFile raf = new RandomAccessFile("test.txt");
FileChannel fc = raf.getChannel();
fc.lock();
System.out.println(raf.readLine()); // (1)
readFile(); // (2)
fc.release();
private
g*****g
发帖数: 34805
5
来自主题: Java版 - 新手问一个多线程的问题
You have to synchronize on the class lock in your case,
or your can use FileLock

private
m******t
发帖数: 2416
6
来自主题: Java版 - 新手问一个多线程的问题

There is a FileLock API.
p**5
发帖数: 2544
7
来自主题: Statistics版 - sas error in unix
when I tried to open a sas file, it says:
ERROR: File is locked, but no other information is available.
I tried to run sas with
$ sas -filelocks continue
which does not solve the problem.
any hints?
(共0页)