Connecting Tech Pros Worldwide Forums | Help | Site Map

Thread-safe file locking

Matt Brandt
Guest
 
Posts: n/a
#1: Sep 15 '07
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


Ian Collins
Guest
 
Posts: n/a
#2: Sep 15 '07

re: Thread-safe file locking


Matt Brandt wrote:
Quote:
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 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.
Ron AF Greve
Guest
 
Posts: n/a
#3: Sep 15 '07

re: Thread-safe file locking



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" <ian-news@hotmail.comwrote in message
news:5l0rieF5q924U1@mid.individual.net...
Quote:
Matt Brandt wrote:
Quote:
>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 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.

Rolf Magnus
Guest
 
Posts: n/a
#4: Sep 15 '07

re: Thread-safe file locking


Matt Brandt wrote:
Quote:
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?
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.

CBFalconer
Guest
 
Posts: n/a
#5: Sep 15 '07

re: Thread-safe file locking


Matt Brandt wrote:
Quote:
>
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?
Both threads and C++ are off-topic here (on c.l.c). We never heard
of a PID either. F'ups set.

--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net>



--
Posted via a free Usenet account from http://www.teranews.com

ks
Guest
 
Posts: n/a
#6: Sep 15 '07

re: Thread-safe file locking


On Sep 14, 9:38 pm, CBFalconer <cbfalco...@yahoo.comwrote:
Quote:
Matt Brandt wrote:
>
Quote:
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.
>
Quote:
How does one maintain file locking between sibling threads?
>
Both threads and C++ are off-topic here (on c.l.c). We never heard
of a PID either. F'ups set.
Is your advertisement off topic?

Ian Collins
Guest
 
Posts: n/a
#7: Sep 15 '07

re: Thread-safe file locking


Ron AF Greve wrote:

Please stop top posting. Your reply wasn't even a follow up to mine.

--
Ian Collins.
Matt Brandt
Guest
 
Posts: n/a
#8: Sep 15 '07

re: Thread-safe file locking


OK, well which ones then?

On 15 Sep 2007 at 12:06, Rolf Magnus wrote:
Quote:
Matt Brandt wrote:
>
Quote:
>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?
>
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.
>
Walter Roberson
Guest
 
Posts: n/a
#9: Sep 15 '07

re: Thread-safe file locking


In article <slrnfeoimm.8vs.spamoff@nospam.invalid>,
Matt Brandt <mattg@mailinator.comtop-posted
Quote:
>On 15 Sep 2007 at 12:06, Rolf Magnus wrote:
Quote:
>Matt Brandt wrote:
Quote:
Quote:
Quote:
>>I am trying to get multiple threads to lock specific regions of a file.
Quote:
Quote:
>To do what you want, you have to resort to
>system-specific libraries.
Quote:
>OK, well which ones then?
Putting on my mind-reading hat....

....
...
...
...
Got it!

On your system, you need nerf_lock(), quizzle84(),
and (especially), StopTopPosting()
--
"law -- it's a commodity"
-- Andrew Ryan (The Globe and Mail, 2005/11/26)
Duane Hebert
Guest
 
Posts: n/a
#10: Sep 15 '07

re: Thread-safe file locking



"Matt Brandt" <mattg@mailinator.comwrote in message
news:slrnfeoimm.8vs.spamoff@nospam.invalid...
Quote:
OK, well which ones then?
Boost has a thread library. Qt has one as well. Hard to say without
knowing what you use.


Ian Collins
Guest
 
Posts: n/a
#11: Sep 15 '07

re: Thread-safe file locking


Duane Hebert wrote:
Quote:
"Matt Brandt" <mattg@mailinator.comwrote in message
news:slrnfeoimm.8vs.spamoff@nospam.invalid...
Quote:
>OK, well which ones then?
>
Boost has a thread library. Qt has one as well. Hard to say without
knowing what you use.
>
Or even which language...

--
Ian Collins.
Duane Hebert
Guest
 
Posts: n/a
#12: Sep 16 '07

re: Thread-safe file locking



"Ian Collins" <ian-news@hotmail.comwrote in message
news:5l33upF5ius4U20@mid.individual.net...
Quote:
Duane Hebert wrote:
Quote:
>"Matt Brandt" <mattg@mailinator.comwrote in message
>news:slrnfeoimm.8vs.spamoff@nospam.invalid...
Quote:
>>OK, well which ones then?
>>
>Boost has a thread library. Qt has one as well. Hard to say without
>knowing what you use.
>>
Or even which language...
Missed the cross post. If the OP is using C only,
pretty much lets out my suggestions...


Gianni Mariani
Guest
 
Posts: n/a
#13: Sep 16 '07

re: Thread-safe file locking


Matt Brandt wrote:
Quote:
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?
You should not be using file locking to protect between the same
threads. On the other hand, if the file handles are different, it may
be that file locking will work even within the same thread on different
file handles.
Walter Roberson
Guest
 
Posts: n/a
#14: Sep 16 '07

re: Thread-safe file locking


In article <46ec99f1$0$32451$5a62ac22@per-qv1-newsreader-01.iinet.net.au>,
Gianni Mariani <gi3nospam@mariani.wswrote:
Quote:
>Matt Brandt wrote:
Quote:
>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.
Quote:
Quote:
>How does one maintain file locking between sibling threads?
Quote:
>You should not be using file locking to protect between the same
>threads. On the other hand, if the file handles are different, it may
>be that file locking will work even within the same thread on different
>file handles.
Unfortunately your answer to this off-topic question was not correct.
POSIX, for example, defines most attributes as being related to
the file descriptor (fd), not the file handle (FILE*) --
but when it comes to POSIX locking:

NOTES
Locks are on files, not file descriptors. That is, file descriptors
duplicated through dup(3C) (but not through fork(2), see the BUGS section
below) do not result in multiple instances of a lock, but rather multiple
references to a single lock.

This has some interesting and probably unintended consequences that can
result in early loss of the lock.

Correct locking is platform specific, and needs to be referred to
a platform specific newsgroup.
--
"It is important to remember that when it comes to law, computers
never make copies, only human beings make copies. Computers are given
commands, not permission. Only people can be given permission."
-- Brad Templeton
Richard
Guest
 
Posts: n/a
#15: Sep 16 '07

re: Thread-safe file locking


CBFalconer <cbfalconer@yahoo.comwrites:
Quote:
Matt Brandt wrote:
Quote:
>>
>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?
>
Both threads and C++ are off-topic here (on c.l.c). We never heard
of a PID either. F'ups set.
Really? You must be a hobbyist programmer.

I have never heard of "F'ups".

"We" speak English is this news group. Kindly be courteous and consider
people whose first language is not English and would have problems
decoding your awful tendency to "jive" in your replies.
Quote:
>
--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net>
Andre Kostur
Guest
 
Posts: n/a
#16: Sep 17 '07

re: Thread-safe file locking


Richard <rgrdev@gmail.comwrote in news:7v642a8l9t.fsf@individual.net:
Quote:
CBFalconer <cbfalconer@yahoo.comwrites:
>
Quote:
>Matt Brandt wrote:
Quote:
>>>
>>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?
>>
>Both threads and C++ are off-topic here (on c.l.c). We never heard
>of a PID either. F'ups set.
>
Really? You must be a hobbyist programmer.
>
I have never heard of "F'ups".
F'ups: Follow-ups. That particular contraction has been used on USENET
for decades now...
Closed Thread