473,732 Members | 2,201 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 5243
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.programmin g.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******@hotma il.comwrote in message
news:5l******** ****@mid.indivi dual.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.programmin g.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...@yah oo.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***@mailinat or.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***@mailinat or.comwrote in message
news:sl******** ************@no spam.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

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

Similar topics

14
2177
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 block and ensuing output. Seems like the output should be all interleaved and of course it's not. Running Python 2.2 from ActiveState on Windows XP (also doesn't work on Windows 2000). Thanks in advance! adeger
7
2703
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 that. Problem is that when program is started many threads are created (see output section), when only two should be running at any time. Can you please help me to identify me where the problem is? Best regards
4
5432
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 server. Data is sent and received over these connections using the asynchronous model. The server is currently in beta testing. Sporadically over the course of the day, I'll observe the thread count on the process (via perfmon) start climbing....
5
2830
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 references to it. But what about threads? If I start a new thread that only does 1+1, is it garbage collected after that? If so, do all threads get garbage collected eventually that are 'done'? And if not, why not? Are there references to the thread that...
16
3309
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 have a thread "_itTaskThread" running. The application is listening on a TCP port. It accepts 2 connection from a client. I simulate a crash on the client side (using "Debug->StopDebugging").
9
3077
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 System.Threading.ThreadInterruptedException System.Threading.ThreadStateException to see if I could get more information about why the thread stops running but that code is never executed. Any ideas on how I can debug this?
13
5091
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 only 1 thread per line Trunk_Thread.ApartmentState = ApartmentState.STA
7
2694
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 a lock pending, for example. I want to be able to stop a thread temporarily, and then optionally resume it or stop it for good.
4
6219
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 Function */ template < class FunType, class ArgType> Thread makeThread(Funtype fun, ArgType arg)
3
35322
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 accessing the database and servicing queries, aren't slowed as much. John Nagle
0
8946
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8774
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9307
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9235
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9181
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6031
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4809
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3261
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.