Will interlocked operation only prevent other interlocked operation on the same location or any visit to the same location?
when reading
https://msdn.microsoft.com/en-us/magazine/cc163715.aspx , i found the following statement:
interlocked operations guarantee that the update is atomic. This requires the processor to insure that no other processor is also trying to execute an interlocked operation on the same location at the same time.
my question is, what if other thread is trying to read the same location at the same time without using a interlocked operation, will an interlocked operation prevent this?
I was using a readerwriter lock to sync my threads operation on an object. and i found interlocked.compareexchange is handy to initialize the object: interlocked.compareexchange(ref object, FunctionThatReturnAnIntializedObject(),null). However, i am not
sure whether other threads can read that object during the interlocked operation? If they can, how can i prevent them?
"However, i am not sure whether other threads can read that object during the interlocked operation? If they can, how can i prevent them?"
If I understand correctly you're trying to lazy initialize a variable.
Why aren't you using Lazy<T> to begin with, it does exactly what you want if you use LazyThreadSafetyMode.PublicationOnly.
But to answer to your question: mixing interlocked and non-interlocked accesses is problematic. There are a lot of cases where doing this won't work and some cases where it works.
In your particular case this interlocked/non-interlocked mix should work fine. In addition to being atomic .NET's interlocked operations are also supposed to be full fences. A full fence prevents other read/writes from being moved before/after the interlocked
operation and that's exactly what you need to prevent the writes required to initialize the object from being moved after interlocked.
If the thread that doesn't use interlocked to read the object variable gets a non-null reference then it means that the initialization of the object was done, otherwise it couldn't have got a non-null reference in the first place.
There is a small chance to run into a problem caused by compiler optimizations. If the thread that doesn't use interlocked has a loop like the following then it's possible that the loop will never end.
while (object == null) { ... }
That's because in the absence of volatile and interlocked the compiler can read "object" into a register before the loop. The loop test will keep comparing the register value with null and the loop will never end. Such a situation is rather unlikely
but you should make the object variable volatile to avoid this.
Similar Messages
-
The phone is stuck on that screen once it is turned on and then turns itself right back off. Unfortunately it doesn't appear the phone was backed up on Icloud. The software update came through on my settings and I performed the update, ever since I have lost over a year and a half of information, pictures etc. Any ideas at all would be appreciated.
If you have not set up iCloud backup or backed up using iTunes, all data on the phone was lost once it entered recovery mode.
Your only option is to restore it and start new.
~Lyssa -
The airport only finds other networks. Not the home network which I have used before.
It doesn't help to search for new networks, try to manually search or add the network. Doesn't
help to turn off/on the airport or even the mac. Doesn't help to reboot the home network - which is
found and connected on the iPhone and iPad. (and network speed is good enough for many devices).
The network just doesn't come up on the list of available networks.
No chance to update software, since got no internet.I did some googling and found alot of topics from you on this issue, to me it simply seems like on of the connectors is broken or loose.
-
When I try to save a file using Excel 2008, ver 12.3.3, with extension either .xlsx or .xls, I get a message saying it cannot be saved because it is "read only." How do I change it from read only? (And how did it ever get to be read only?)
Save the file as a new name. Close and Open the new file.
Most likely when a file transfer happens, Office makes the file 'Read Only'.
If you have two opened files with the same name, the last opened file will be 'Read Only'. -
Tried to open an app and my iPad gen one froze. It only shows the apple on black screen and will show the operating wheel sometimes and while plugged in it will beep every few minutes. Will not load one show anything on screen but the small white apple.
Try:
- iOS: Not responding or does not turn on
- Also try DFU mode after try recovery mode
How to put iPod touch / iPhone into DFU mode « Karthik's scribblings
- If not successful and you can't fully turn the iOS device fully off, let the battery fully drain. After charging for an least an hour try the above again.
- Try on another computer
- If still not successful that usually indicates a hardware problem and an appointment at the Genius Bar of an Apple store is in order.
Apple Retail Store - Genius Bar -
When i try to make a iMovie project it will say operation could not be completed and no other info
when i try to make a iMovie it will say operation could not be completed and no other info is available
I saw someone else had this issue back in July, and the solution was to create a new event and then a new movie within that event. I tried this and it did not work for me.
-
CS6 Camera Raw - I can now only crop using aspect ratio in the custom crop setting rather than being able to set the dims in cm and inches? anyone know how to revert? ever since installing new mac operating system things have been strange!
Hi Kglad.
I have looked at all of my settings both in Bridge and CS6 Photoshop regarding Camera Raw. I am at a loss how to set the crop tool in cm or inches as I once did - now the only option is to crop using ratios of 1:1 etc etc - This is infuriating as lots of my square crops I could set at 10" x 10'' specifically to print one to one to fit frame and mount size -
Now if cropping using bloody aspect ratio of 1:1 (square) the actual dims of the crop are roughly 4.25 inches x 4.25 inches. this means I then have to open the whole image in photoshop in order to crop at the dims I have set! It was so much quicker in terms of batch cropping in camera raw being able to set dims in centimetres and inches but they have gone and mucked around with it, with the new bloody update! Unless you are an absolute genius and know how I can go back to having an option of CM, Inches and aspect ratio within the custom crop settings? (Please say you do)
here is the new tutorial for CC - my guess is they have scrapped the control we had over the custom crop settings
Cropping Images In Adobe Camera Raw 8 -
Why won't my iMac print consistantly to my compatible HP 6500A? I've checked for updates and downloaded the lasted software...still can't print. All my other Mac devices find the printer but the iMac is hit and miss. I'm operating the Mac OS X Lion 10.7.
When you say hit and miss do you mean sometimes you print a whole document with no problems, or do you mean each document has problems? This is from HP's website for your printer:
Your sig says 10.6.7 but your message says 10.7. So if it's really Lion, this printer isn't officially supported. Elsewhere on HP's site it says updated drivers will be available on your Mac via Software Update. Have you run that recently? -
I would like to use iCloud services more, but I prefer the security of the Google Authenticator 2-step system. I just installed the Apple ID 2-step, but was disappointed to learn that it only prevents account changes and purchases. It will not stop people from accessing your iCloud email or seeing your contacts or any other services you may have with Apple.
Will the Apple ID 2-step take steps to be like the Google Authenticator?The Apple ID & 2-step verification doesn't stop one from logging into iCloud from a browser and then access/delete adderss book info etc. It is frustrating that Apple turned on 2-step but has nothing to extend or implement it for iCloud. When I called their tech support I was told that it will be rolled out shortly. Until such time the 2 step in place is pretty much useless.
-
My ipad air will not allow me to access since I downloaded the new version 8.3 operating software
When I try to open the slide to upgrade screen comes up and then the request for passcode and then the apple loading screen then Hello then update completed screen I select continue another apple with line showing progress then asking for password enter then Message and Face time a screen
then a get started screen and then another apple with line showing progress and then my opening screen shows for a split second and then back to the apple with progress for a split second and then it shuts down. -
I get the error message in QuickTime "operation stopped the operation is not supported for this media" most times when I try and export an .AVI file as something else (e.g. .m4v). I have not touched the file in any way (no trimming, clipping or other editing), all I want QuickTime to do is export the file in a compressed format. Bizzarely, if I shutdown and open QuickTime many times I can occasionally export a clip as another format (maybe one in 10 times). I have seen that other users have had a similar problem after clipping files in QuickTime but this seems to be a slightly different bug in that all I do is open the file and then try and export the file as is - either way, this is a very annoying bug
@Z_B-B, thank you for taking the time to respond to my cry for help. However, the link you supplied does not address the problem: I am not trying to export from Final Cut Pro to QuickTime, I am trying to export from QuickTime to the rest of the world (like people's iPhones and Ipads) in .m4v format (so I am not emailing my freinds such huge files).
If I were to spend hundreds of Dollars on a copy of Final Pro I could export directly from there and not have to bother with QuickTime, but I do not take enough video clips to justify the cost. I must say that I never had any of these problems before I decided to switch from Snow Leopard to Mountai Lion. -
iMac 7.1 (2.47 Ghz Intel Core Duo w/2GB memory) operating OSX v 10.9.5. At the core level I find two Library folders, one within the System Folder and one by itself with the other core level folders - mostly same content. Is this right or do I have a duplication problem?
The system is slow. -
Sync from iPhone to iCal on MacBook has failed since the latest iPhone upgrade, yesterday. It's worked in reverse, and all other sync operations appear to have worked. Any solutions, that I may not have already tried (over and over)
(Sorry, first time user of these forums, and it's confusing in it's own right)You may have to try deleting all the music from your phone (by going to Settings>General>Usage>Music, swipping All Music and tapping Delete), then sync it all back on with iTunes in order to fix this.
-
My iphone 4s will only text other iphones
my son's iphone 4s will only text other iphones & isn't calling out. anyone else have this problem?
It does sound like your son is using iMessage. Try turning it off on his phone. Also, if he can receive calls, then the phone does have cellular service. Try rebooting the phone. Hold down the power and home keys at the same time until you see the Apple logo. Ignore the "Slide to ...." message. Leave the phone off for a few minutes, then power up.
-
my iphone will not connect to my wifi only just started to do this the last 2 days sometimes the wifi turns on other time no often then not it will not turn on could u help ?
Settings > General > Reset > Reset Network Settings.
Basic troubleshooting from the User's Guide is reset, restart, restore (first from backup then as new). Try each of these in order until the issue is resolved.
If the problem is still not resolved, take the device to Apple for evaluation and possible replacement.
Verizon does not provide hardware support, taking the device to them would be a waste of time.
Maybe you are looking for
-
The line to type in under the tabs has disappeared. How do I get it back?
The line under the tabs-where I could type in a question, web site or view the web site address is missing. How do I get it back?
-
How to migrate attachments from legacy system to SAP.
Hello experts, We have a requirement to migrate attachments from a legacy application to SAP .Attachments are in the form of a PDF, xls, powerpoints. These are to be attached to accounts, opportunities etc. Please provide y
-
wil it be possiblt to create a form where we can drag the change the width of the columns in the form. How can this be accomplished?
-
Since the last update of evince to 0.83 it won't open pdf files no more - I get: Unable to open document Unhandled MIME type: "application/pdf" Is this a bug? I can open pdfs using kpdf or kghostview without a problem.
-
Dispatch Event for loaded Netconnection datas
Hi All! I made a manager component to retrieve data from database through amfphp. When the datas are loaded at the end of the "onResult" function, I dispatch an event "contactLoader" Another parent mxml component has an instance of my manager compone