线程安全文件锁定 [英] Thread-safe file locking

查看:64
本文介绍了线程安全文件锁定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试获取多个线程来锁定文件的特定区域。

但是,由于每个线程都具有相同的PID,因此看起来锁定了

一个线程不会阻止来自同一进程的另一个线程。


如何在兄弟线程之间保持文件锁定?


- Matt

I am trying to get multiple threads to lock specific regions of a file.
However, since each thread has the same PID, it appears that a lock by
one thread does not block another thread from the same process.

How does one maintain file locking between sibling threads?

- Matt

推荐答案

Matt Brandt写道:
Matt Brandt wrote:

我试图获得多个线程锁定文件的特定区域。

但是,由于每个线程具有相同的PID,看起来一个线程的锁定不会阻止来自同一个线程的另一个线程进程。


如何在兄弟线程之间维护文件锁定?
I am trying to get multiple threads to lock specific regions of a file.
However, since each thread has the same PID, it appears that a lock by
one thread does not block another thread from the same process.

How does one maintain file locking between sibling threads?



comp.programming.threads或OS编程组这将是一个更合适的地方。 C和C ++都没有标准线程

或文件锁定支持。


-

Ian Collins。

comp.programming.threads or an OS programming group would be a more
appropriate place to ask this. Neither C nor C++ have standard thread
or file locking support.

--
Ian Collins.







也许在程序中使用一段代码来跟踪哪个线程

锁定了哪个区域。使用互斥锁修改该段代码。大多数

系统支持互斥(例如sunos,MS-Windows和我相信linux)

..

问候,Ron AF Greve

http://www.InformationSuperHighway.eu


" Ian Collins" < ia ****** @ hotmail.comwrote in message

news:5l ************ @ mid.individual.net ...

Hi,

Maybe use a piece of code in your program to keep track of which thread
locked which region. Protrecting that piece of code with a mutex. Most
system support mutexes ( for instance sunos, MS-Windows and I believe linux)
..
Regards, Ron AF Greve

http://www.InformationSuperHighway.eu

"Ian Collins" <ia******@hotmail.comwrote in message
news:5l************@mid.individual.net...

Matt Brandt写道:
Matt Brandt wrote:

>我正在尝试获取多个线程来锁定文件的特定区域。
但是,由于每个线程具有相同的PID,看起来一个线程的锁定不会阻止来自同一进程的另一个线程。

如何保持文件锁定兄弟之间的线程之间?
>I am trying to get multiple threads to lock specific regions of a file.
However, since each thread has the same PID, it appears that a lock by
one thread does not block another thread from the same process.

How does one maintain file locking between sibling threads?



comp.programming.threads或OS编程组将是一个更合适的地方。 C和C ++都没有标准线程

或文件锁定支持。


-

Ian Collins。

comp.programming.threads or an OS programming group would be a more
appropriate place to ask this. Neither C nor C++ have standard thread
or file locking support.

--
Ian Collins.



Matt Brandt写道:
Matt Brandt wrote:

我试图获得多个线程锁定文件的特定区域。

但是,由于每个线程具有相同的PID,看起来一个线程的锁定不会阻止来自同一个线程的另一个线程过程。


如何在兄弟线程之间保持文件锁定?
I am trying to get multiple threads to lock specific regions of a file.
However, since each thread has the same PID, it appears that a lock by
one thread does not block another thread from the same process.

How does one maintain file locking between sibling threads?



标准C和C ++都假设除了

之外没有其他任何东西在运行你的程序,而且这两种语言都不支持线程。因此,

没有文件锁定的概念。要做你想做的事,你必须求助于

系统特定的库。

Both Standard C and C++ assume that there is nothing else running besides
your program, and both languages don''t support threads. Therefore, there is
no concept of "file locking". To do what you want, you have to resort to
system-specific libraries.


这篇关于线程安全文件锁定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆