473,387 Members | 1,641 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Thread-safe file locking

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

Sep 15 '07 #1
15 5191
Matt Brandt wrote:
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.
Sep 15 '07 #2

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 wrote:
>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.

Sep 15 '07 #3
Matt Brandt wrote:
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.

Sep 15 '07 #4
Matt Brandt wrote:
>
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

Sep 15 '07 #5
ks
On Sep 14, 9:38 pm, CBFalconer <cbfalco...@yahoo.comwrote:
Matt Brandt wrote:
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.
Is your advertisement off topic?

Sep 15 '07 #6
Ron AF Greve wrote:

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

--
Ian Collins.
Sep 15 '07 #7
OK, well which ones then?

On 15 Sep 2007 at 12:06, Rolf Magnus wrote:
Matt Brandt wrote:
>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.
Sep 15 '07 #8
In article <sl********************@nospam.invalid>,
Matt Brandt <ma***@mailinator.comtop-posted
>On 15 Sep 2007 at 12:06, Rolf Magnus wrote:
>Matt Brandt wrote:
>>I am trying to get multiple threads to lock specific regions of a file.
>To do what you want, you have to resort to
system-specific libraries.
>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)
Sep 15 '07 #9

"Matt Brandt" <ma***@mailinator.comwrote in message
news:sl********************@nospam.invalid...
OK, well which ones then?
Boost has a thread library. Qt has one as well. Hard to say without
knowing what you use.
Sep 15 '07 #10
Duane Hebert wrote:
"Matt Brandt" <ma***@mailinator.comwrote in message
news:sl********************@nospam.invalid...
>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.
Sep 15 '07 #11

"Ian Collins" <ia******@hotmail.comwrote in message
news:5l*************@mid.individual.net...
Duane Hebert wrote:
>"Matt Brandt" <ma***@mailinator.comwrote in message
news:sl********************@nospam.invalid...
>>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...
Sep 15 '07 #12
Matt Brandt wrote:
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.
Sep 16 '07 #13
In article <46***********************@per-qv1-newsreader-01.iinet.net.au>,
Gianni Mariani <gi*******@mariani.wswrote:
>Matt Brandt wrote:
>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.
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
Sep 16 '07 #14
CBFalconer <cb********@yahoo.comwrites:
Matt Brandt wrote:
>>
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.
>
--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net>
Sep 16 '07 #15
Richard <rg****@gmail.comwrote in news:7v************@individual.net:
CBFalconer <cb********@yahoo.comwrites:
>Matt Brandt wrote:
>>>
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...
Sep 17 '07 #16

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: adeger | last post by:
Having trouble with my first forays into threads. Basically, the threads don't seem to be working in parallel (or you might say are blocking). I've boiled my problems to the following short code...
7
by: Ivan | last post by:
Hi I have following problem: I'm creating two threads who are performing some tasks. When one thread finished I would like to restart her again (e.g. new job). Following example demonstrates...
4
by: Matthew Groch | last post by:
Hi all, I've got a server that handles a relatively high number of concurrent transactions (on the magnitude of 1000's per second). Client applications establish socket connections with the...
5
by: Razzie | last post by:
Hi all, A question from someone on a website got me thinking about this, and I wondered if anyone could explain this. A System.Threading.Timer object is garbage collected if it has no...
16
by: droopytoon | last post by:
Hi, I start a new thread (previous one was "thread timing") because I have isolated my problem. It has nothing to do with calling unmanaged C++ code (I removed it in a test application). I...
9
by: mareal | last post by:
I have noticed how the thread I created just stops running. I have added several exceptions to the thread System.Threading.SynchronizationLockException System.Threading.ThreadAbortException...
13
by: Bob Day | last post by:
Using vs2003, vb.net I start a thread, giving it a name before start. Code snippet: 'give each thread a unique name (for later identification) Trunk_Thread.Name = "Trunk_0_Thread" ' allow...
7
by: Charles Law | last post by:
My first thought was to call WorkerThread.Suspend but the help cautions against this (for good reason) because the caller has no control over where the thread actually stops, and it might have...
4
by: jayesah | last post by:
Hi All, I am writting a Thread class with using pthread library. I have some problem in saving thread function type and argument type. How to make Thread class generic ? /* This is my global...
3
by: John Nagle | last post by:
There's no way to set thread priorities within Python, is there? We have some threads that go compute-bound, and would like to reduce their priority slightly so the other operations, like...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.