Parallel Computing Developer Center >
Parallel Computing Forums
>
Parallel Extensions to the .NET Framework
>
LazyInitMode.AllowMultipleExecution
LazyInitMode.AllowMultipleExecution
- About a month ago there was a post on the PFX blog Do you use LazyInitMode.AllowMultipleExecution?
As suggested in that Post, I also think this mode has little use. It will allow multiple threads to execute and thereby prevent them from beeing blockd. But if I have the choice between blocking a thread or having two threads do the same thing and throw away the result of one of them I will always choose to block. Waiting in my opinion is not a bad thing if there is nothing usefull to do.
I also noticed that in Beta 1 this option has been renamed into AllowMultipleThreadSafeExecution
While this name does state what it does I do think it can be confusing. A developer new to this API might think that AllowMultipleThreadSafeExecution will be 'safer' then EnsureSingleThreadSafeExecution. As it suggests that the first is even thread safe when using multiple threads, but the latter is only safe when there is just one thread.
So if you ask me (and you did) I would drop this option, if only it were to prevent developers to use it by mistake. Another option would be to create two searate switches, one for ThreadSafety, and one for multiple execution. In any case it shoud be made more clear than it is now that NotThreadSafe and EnsureSingleThreadSafeExecution are the preferred options (depending on the scenario ofcourse).- Changed TypeStephen Toub - MSFTMSFT, ModeratorTuesday, June 16, 2009 2:11 AM
All Replies
- Hi Frank,
"As suggested in that Post, I also think this mode has little use. It will allow multiple threads to execute and thereby prevent them from beeing blockd. But if I have the choice between blocking a thread or having two threads do the same thing and throw away the result of one of them I will always choose to block. Waiting in my opinion is not a bad thing if there is nothing usefull to do."
Well, the performance issue is that when blocking it is always blocking, not just for the first time. So, if you have many access to the instance you might loose time.
As opposite to non-blocking mode when the possible hit is only if/when two or more threads access the variable for the first time. I see the benefits of this second mode as the "bad" scenario might even not happen at all and after that you have no peformance issues anymore.
Miha Markic [MVP C#] http://blog.rthand.com - Frank,Thanks for the feedback! We will definitely take it into account. The bit about the naming is particularly helpful.Thanks,Josh
- Proposed As Answer byJosh PhillipsMSFTMonday, June 15, 2009 4:47 PM


