Multithreading: Safe to have two readers on data without locks?

I'm still trying to fully grasp locking / multi-threading issues. I
know locks are required whenever reader and writers interact with the
same data on different threads.

However, if you have two seperate threads reading a piece of data, but
the data is not being written to by anything while those threads are
processing, is a lock required if the threads have a chance of
executing the read at the same time, or is it safe to have multiple
read-only attempts to a piece of data?

Thanks,
Josh McFarlane

0
darsant (187)
7/6/2005 4:52:56 PM
vc.mfc 33608 articles. 0 followers. Follow

4 Replies
415 Views

Similar Articles

[PageSpeed] 13

If you KNOW that nothing will ever write to them while your reader threads 
are active then no, no need to lock them.

-- 
- Mark Randall
http://zetech.swehli.com

"Josh McFarlane" <darsant@gmail.com> wrote in message 
news:1120668776.800055.127370@g43g2000cwa.googlegroups.com...
> I'm still trying to fully grasp locking / multi-threading issues. I
> know locks are required whenever reader and writers interact with the
> same data on different threads.
>
> However, if you have two seperate threads reading a piece of data, but
> the data is not being written to by anything while those threads are
> processing, is a lock required if the threads have a chance of
> executing the read at the same time, or is it safe to have multiple
> read-only attempts to a piece of data?
>
> Thanks,
> Josh McFarlane
> 


0
markyr1 (230)
7/6/2005 5:14:47 PM
On 6 Jul 2005 09:52:56 -0700, "Josh McFarlane" <darsant@gmail.com>
wrote:

>I'm still trying to fully grasp locking / multi-threading issues. I
>know locks are required whenever reader and writers interact with the
>same data on different threads.
>
>However, if you have two seperate threads reading a piece of data, but
>the data is not being written to by anything while those threads are
>processing, is a lock required if the threads have a chance of
>executing the read at the same time, or is it safe to have multiple
>read-only attempts to a piece of data?
>

In this specific case, no.  How sure are you that in the future you
won't decide to add new capability to your system which inadvertently
includes write access to the same data?  In general, learning to use
synchronization methods properly and then always doing it whether
"needed" or not is much better practice.  Once you get over the
initial hurdle, it isn't so bad.


0
r
7/6/2005 5:19:22 PM
r norman wrote:
> In this specific case, no.  How sure are you that in the future you
> won't decide to add new capability to your system which inadvertently
> includes write access to the same data?  In general, learning to use
> synchronization methods properly and then always doing it whether
> "needed" or not is much better practice.  Once you get over the
> initial hurdle, it isn't so bad.

I plan on using them whenever I multithread. This was one of those
questions I didn't know the answer to and wanted to know more for a
theory purpose than in my actual programming style, in case I need it
in the future to debug, and just for expanding my knowledge.

Thanks.

0
darsant (187)
7/6/2005 5:24:06 PM
There is no need to lock read-only access. There is no need to lock unless you are
modifying several related fields or any multibyte field that is not a simple DWORD value.
			joe

On 6 Jul 2005 09:52:56 -0700, "Josh McFarlane" <darsant@gmail.com> wrote:

>I'm still trying to fully grasp locking / multi-threading issues. I
>know locks are required whenever reader and writers interact with the
>same data on different threads.
>
>However, if you have two seperate threads reading a piece of data, but
>the data is not being written to by anything while those threads are
>processing, is a lock required if the threads have a chance of
>executing the read at the same time, or is it safe to have multiple
>read-only attempts to a piece of data?
>
>Thanks,
>Josh McFarlane

Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
0
newcomer (15975)
7/7/2005 6:53:12 AM
Reply:

Similar Artilces:

2003 Excel Pivot table data selection
I am currently trying to create a PT but my source data is more than the 65k row limit. Can you create a PT using source data from 2 worksheets and if so, How? ...

numbers in excel it automatically adds two decimal points in the .
If I'm typing a number in Excel 2003 and it doens't contain any decimal points, Excel automatilly adds one or two for me. The example I indicated above refers to me entering "8" (for the number of hours worked in a day) and after typing it, it appears as "0" in the cell and ".08" in the total column. I've tried Format > Numbers > Text and this works, but I have to do it on an individual basis. I'd like to turn this off completely. Hi goto 'Tools - Options - Edit' and uncheck 'Fixed Decimals' -- Regards Frank Kabel Frank...

Question about the Common Application Data Folder
I'm confused about how to use the CommonAppData Folder in Visual Studio. I need for my deployment project to put some files on the disk. Then, my application needs to find those files. I can use the deployment project to put files into [CommonAppDataFolder]\[Manufacturer]\[ProductName], or any variation on that. However, I can't figure out how to reference that folder from within the code. Conversely, I can use Application.CommonAppDataPath to find files in [CommonAppDataPath]\[CompanyName]\[ProductName]\[ProductVersion]. However, I can't figure out how to make the ...

data
Hi, I transported data into excel. I have values in A10, A20, A30, A40 etc.... A1000 I want to delete all the empty cells. So, B1 should be A10 B2 should be A20 B3 should be A30 B4 should be A40 If I enter the formula in B1: =A10 B2: =A20 etc. I cannot copy the formula, if I copy it the formula in B3 is A12 and it should be A30. I hope someone can help me. -- melle ------------------------------------------------------------------------ melle's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=26981 View this thread: http://www.excelforum.com/showt...

Savs All Forex Data
Hi there, I want to save forex currency data into excel sheet. Forex refreshes the data every 15 seconds. How to save all data without overwrite the old one. Thanks in advance. YJL -- YJL ------------------------------------------------------------------------ YJL's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=28693 View this thread: http://www.excelforum.com/showthread.php?threadid=490703 Hi Record a macro, "open a new sheet" then copy forex and paste as value on new sheet, and save" then stop recording Macro. Your Forex on the main sh...

How to alter data on HTML webpage into Excell cells as numbers?
A saved HTML webpage is opened with Excel 2003. The HTML webpage has columns of numerical data which go into Excel cells. If we operate on the Excell cells, the contents of the cells do not behave like numbers. This is so also after formatting the cells as numbers. However on the same spreadsheet the other blank cells are properly reformatted as numbers. Simple... When a cell is formated as text and has numaric data in it, changing the format to number or currency will not work. Even thought the format in the Format cell pop up box appears to be in number or currency format. There are ma...

About better data quality
Hello, Thanks for the help on the last question. We have looked at several open source offers in the field of data integration. We are now wanting data quality software to complete our data integration program. Do packages exist to suit our needs? Would you know of innovative data quality programs? Thanks to all! This newsgroup answers questions pertaining to Access, a relational database application that is part of Microsoft Office Professional. -- Build a little, test a little. "Guertas" wrote: > Hello, > > Thanks for the help on the l...

answer to multiple validation data lists
I posted a few days ago a question on how to make multiple validation lists... I found a VERY simple work around just by trial and error and thought I'd share. In my example, i am making a computer system configurator and will make an example here.. Cell A1 has a list of motherboards, let's say 2 of them. Part #'s in the list are as follows MOTHERBOARDA MOTHERBOARDB Based on that selection, a list of chassis comes up. The list of compatible chasssis for each motherboard is named after the motherboard selection (as required) "MOTHERBOARDA" and "MOTHERBOARDB" s...

How do I import data
I have an ACT! 2000 Database (.dbf) and would like to import to CRM. Any ideas on how to go about doing this would be great. You have a couple of options here: 1. Use the Microsoft CRM Data Migration Framework toolkit - available to download with documentation: http://www.microsoft.com/downloads/details.aspx?FamilyID=0c3f1734-23e2-4e60-a42d-01a36a9f9831&DisplayLang=en 2. Check out www.scribesoft.com who have a direct import tool from ACT to CRM 3. If you just want to bring in Contacts you could export your ACT contacts to a csv file and then directly import into crm using the Conta...

Memory Leak in Visio Data Refresh
Hi There, I am using the built-in data refresh in Visio 2007. I am automatically refresh every 3 minutes. What I have found is that the MemUsage incrementally increases after each data refresh until I get an error message of not having enough virtual memory. Is there a work around besides closing Visio down and restarting again after some hours? This also happens using a macro that microsoft suggested: intCount = ThisDocument.DataRecordsets.Count Set vsoDataRecordset = ThisDocument.DataRecordsets(intCount) vsoDataRecordset.Refresh --- frmsrcurl: http://msgroups.net/microsoft.public...

Move data to another sheet
I am trying to move data from one worksheet to another moving only lines with data. This is what I have A B C D E F Cost Code ...

Update CRM Data using vb.net
Hi, I am new to CRM. I am trying to retrive and update information into CRM using my VB.Net application. I am able to retrieve information from CRM. But i am not able to update. Can any one tell me how to update contact information using VB.Net. If any sample program it will help me to create some applications. Thanks in advance. Phani Check out the Microsoft CRM examples on msdn.microsoft.com - a number of these show updfating data "Phani" <phanimadhavsv@hotmail.com> wrote in message news:Ow5xjhnWDHA.2064@TK2MSFTNGP11.phx.gbl... > Hi, > > I am new to CRM. I am...

XL Charts: Let my mouse drag all data labels for a whole series.
Excel charts should allow my mouse to drag all the data labels for a whole series in unison. For example, instead of having to move each data label one-at-a-time to the right of each column, I should be able to move them all together. Aside from the time savings, the greatest advantage would be the ability to move all of the labels a precisely uniform and equal distance from their original locations. This feature would be especially useful when one-or-more series in a stacked column chart is too small to allow enough space to display its labels within the the column -- Stuart Brates...

Add data to excel series
I receive daily API transation data. Each day the data is provided via a text file. Data is in columns. First column is date, second column is API (35 different APIs), third column is transaction volume and fourth column is average response time. I would like to create a chart with date on the x axis, transaction volume on the y axis, and each API as its own series. I can create a base chart for a single day with all series. I am having a problems adding in addition series data for each additional day? Is there an easy way to add data to each series? Create a PivotTable (and PivotC...

Finding Data in multiple worksheets
Using Excel 2000, how can I find data in multiple worksheets; example: any number between 200 & 299 in 32 worksheets? If you mean you want to find a single number across 32 worksheets, group your worksheets (click on the first, ctrl-click on subsequent (or even shift-click)). Then Edit|Find But I think I'd use Jan Karel Pieterse's FlexFind: http://www.oaltd.co.uk/MVP/ If you meant you wanted to find all 100 numbers (200-299) in all 32 sheets, then I think I'd have a macro search for each number and report the results on a new worksheet. "mark@southwestconst.com&quo...

import data from sql on a clean install of CRM (new SID)
I performed a clean install on a new server but can not import or restore my data from my old crm install because the SIDs are differnt and CRM stops working. What can I do to get data to my new database from the old database. My main goal is to get my accounts and contacts back. Everything else I can recreate. Anyone who knows how to solve my issue please lend your assistance. Thanks in advance. If you're just concerned about Accounts and Contacts you should check out the Data Migration Framework. You could also use the Redeployment Tool but you would have to still have yo...

File is locked for editing message
I have excell 2007 and when I try to open a non shared file I created in my network share I get a message that the file is locked for editing. I have ownership of that share and I see no reason why this would come up. Is this an excel issue that can be fixed? Thanks Carl -- When you open a workbook in Excel a temporary copy is created. When you close the workbook the temporary file should be deleted. At times your OS does not do its job and the temp file is left open. This will give you the "locked for editing" message. It is usually necessary to re-boot to clear it o...

Please advice me a good book about windows multithreading.
Hi, all. I was looking for the book, but iam not quite sure. Just give a couple key advices please. >-----Original Message----- >Nikolay wrote: > >> Hi, all. >> I was looking for the book, but iam not quite sure. >> Just give a couple key advices please. > >"Programming Applications for Microsoft Windows" >by Jeffrey Richter. > >(Or an older edition of the same book, which was titled "Advanced Windows". > >-- Tnx. >Scott McPhillips [VC++ MVP] > >. > Nikolay wrote: > Hi, all. > I was looking for the boo...

Two notifications appear for one new email
Can anyone identify why I get two email notification alerts when only one new email arrives? Using MS Outlook 2000 on WinXP machine Thanks. Maybe I solved my own problem...I turned off email notifications, rebooted, and turned it on later. So far so good... Still happening...two email icons display in the system tray as well. And sometimes after reading the new email, one of them disappears while the other remains displayed in the system tray...any ideas? ...

how to compare two bitmaps and give a mark to describe how similar they are
hi, everyone how to compare two bitmaps and give a mark to describe how similar they are? The two bitmaps's size are the same, I can use CDC::GetPixel to get a mark, but this method is inefficient. Any body have any ideas? Thank you very much. take the pixel value of one minus the pixel value of the other and square this difference. So it goes something like difference = 0; for (x=0....) for (y=0....) difference += pow( bitmap1(x,y) - bitmap(x,y) ), 2) You could also use a cross correlation, but that has a built in bias such that a difference around white is more import...

Veritas 9.1 restore without Agent
Hello, I do not have the Veritas Exchange Backup Agent module nor the Advanced Open File option installed on my domain (2 DCs / AD / Win2K). I was wondering if I can still do a full restore of Exchange 2000 in case of a full disaster recovery (clean install of MS Small Business Server 2K)? Please explain any limitations. Thank you in advance, Rocky You can't do an online backup of Exchange with Veritas unless you have the agent....get the agent. Re the open file agent - a lot of opinions on that one. However, even if you get and use it, you shouldn't try to use it to back up Exc...

Interrogating Data in Excel
Hello, Not being an excel wizard I need some help on this one. I have a summary sheet of a number of differnt teams at work, then in four different worksheets I have the same teams and their goals and whether they have met them or not on a rolling weekly basis for 10wks. What I want to do in the summary sheet is say look at this teams performance in Worksheet 1 and if they have failed for the week put a F or colour red in the summary spreadsheet. Then look at the next teams performance and so on. Any ideas would be much appreciated. Daniel, One option would be to use an IF stat...

Customizing for two different companies
I need to make customizations for two differnt companies (one is a subsidary, other is parent). I created a business unit in CRM for each comapny. How do I customizations for one company and different ones for the other company? How do I tell CRM that I want to change, for example, fields on the contact screen for the parent company, and not for the subsidary? Unfortunately, in the currentl release, there is no support for different forms for different users. This won't be seen in the next release either. Some people have tried to so this by installing multple app servers that ea...

How do I import data from a table into a working payables batch?
I trying to create a table to import credit card transactions from our corporate card into a working payables batch so it can be posted to payables module as a normal batch? Any help on how and were to start would be greatly appreciated. Pete Can you get the credit card data as a CSV or Excel file? You could use Integration Manager to import the file. "Pete Kaufman" <Pete Kaufman@discussions.microsoft.com> wrote in message news:87FF509E-3A65-4C08-81C9-5058442C2344@microsoft.com... >I trying to create a table to import credit card transactions from our > corporate...

Calculating no of work days between two dates
Please advise how to calculate the number of work days (excludin weekeends and holidays) between two date -- fluffywhitedo ----------------------------------------------------------------------- fluffywhitedoh's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=3528 View this thread: http://www.excelforum.com/showthread.php?threadid=55075 =NETWORKDAYS(start_date,end_date,holidays) holidays is a range of holiday dates. You will need to have the Analysis Toolpak installed, Tools>Addins, and cheek it. -- HTH Bob Phillips (replace somewhere in email address ...