I have a question on this program. It does not produce the correct result. I assume that it should give me output like + 1 + 2 - 1 + 3 - 2 + 4 - 3 + 5 - 4 - 5 (not order specific). However, it outputs + 1 + 2 - 2 + 3 - 3 + 4 - 4 + 5 - 5 - 5.  If I make a copy       MyStructure msCopy = ms; Thread t = new Thread(() =&gt; { updateMe(msCopy); });   It outputs the correct value. I am using .net 3.5. What is the reason?  class Program {     static void Main(string[] args)     {         Program p = new Program();         p.createThread();     }      List&lt;MyStructure&gt; structure = new List&lt;MyStructure&gt;();      public void createThread()     {         foreach (MyStructure ms in structure)         {             System.Diagnostics.Debug.WriteLine("+ " + ms.ID);             //MyStructure msCopy = ms;             //Thread t = new Thread(() =&gt; { updateMe(msCopy); });             Thread t = new Thread(() =&gt; { updateMe(ms); });             t.Start();         }      }      private void updateMe(MyStructure ms)     {         System.Diagnostics.Debug.WriteLine("- " + ms.ID);     }      public Program()     {         structure.Add(new MyStructure { ID = 1, Name = "A" });         structure.Add(new MyStructure { ID = 2, Name = "B" });         structure.Add(new MyStructure { ID = 3, Name = "C" });         structure.Add(new MyStructure { ID = 4, Name = "D" });         structure.Add(new MyStructure { ID = 5, Name = "E" });     } }  internal class MyStructure {     public int ID { get; set; }     public String Name { get; set; } }
In the two following snippets, is the first one safe or must you do the second one?  By safe I mean is each thread guaranteed to call the method on the Foo from the same loop iteration in which the thread was created?  Or must you copy the reference to a new variable "local" to each iteration of the loop?  var threads = new List&lt;Thread&gt;(); foreach (Foo f in ListOfFoo) {           Thread thread = new Thread(() =&gt; f.DoSomething());     threads.Add(thread);     thread.Start(); }   -  var threads = new List&lt;Thread&gt;(); foreach (Foo f in ListOfFoo) {           Foo f2 = f;     Thread thread = new Thread(() =&gt; f2.DoSomething());     threads.Add(thread);     thread.Start(); }   Update: As pointed out in Jon Skeet's answer, this doesn't have anything specifically to do with threading.
Why is James Bond less tech savvy in the Daniel Craig movies? When do you use “learnt” and when “learned”? Is learnt UK English and learned US? Is it that simple?  I’m used to using learnt, but my US spellchecker says it is wrong. How to reconcile the cashless human/Federation society with human traders and merchants From a variety of sources, including , we know that the Federation (or at least the humans) don't use money. This raises the problem that humans frequently visit worlds where there is currency, and, in the case of DS9, operate a station that has currency frequently in use (for example, Federation personnel frequently attend Quark's bar). Additionally, we see human traders.   My question is, how do humans get "money" (credits, latinum, etc.)? How would a human even get the resources to purchase their own merchant ship or the resources to fill its cargo holds with merchandise? If Federation personnel can simply be given money for the asking, why haven't they poured so much money down Quark's throat that he chokes on it? Possible Duplicate:           What book would you recommend for an undergraduate wanting to learn the basics of topology? I've come across several books that claim to give an introduction to the subject, but I wasn't sure which one(s) to pick.  Here are some of the books I came across:   Introduction to Topology - Bert Mendelson Basic Topology - M.A. Armstrong First Concepts of Topology - William G. Chinn Topology Without Tears - Sidney A. Morris Topology - James Munkres   They don't go over the exact same topics, some are more in-depth than others, some seem to target slightly different audiences etc. What would be right for me (not necessarily from that list)? To give some more background, I want to learn topology because I feel it will be somewhat helpful in the field of Computer Vision. I've been investigating the Cartesian graph of $x^y=y^x$. Obviously, part of the graph is comprised of the line $y=x$ but there is also a curve that is symmetrical about the line $y=x$. (We can prove this symmetry by noting that the function $x^y=y^x$ is self-inverse; all self-inverse functions are symmetrical about the line $y=x$.) An image of the graph is shown below:  I decided to find the intersection point and arrived at an intriguing result: the intersection point between the two curves is at $(e,e)$. The following is my method: If the gradient of the line $y=x$ is $1$, the gradient of the curve at the intersection point must be $-1$ as it's a normal to the line (as it's symmetrical about the line). This means that at that point $\frac{dy}{dx}=-1$. Now to find $\frac{dy}{dx}$. We have $x^y=y^x$. I then used a very powerful tehnique for differentiating these sorts of functions. We know that eg $$x^y=e^{\ln{x^y}}=e^{y\ln{x}}$$ and $$\frac{d}{dx}e^{f(x)}=f'(x)e^{f(x)}$$ Applying it to our function $x^y=y^x$ and using implicit differentiation and the product rule gives us: $$(\frac{dy}{dx}\times \ln x +\frac{y}{x})x^y=(\ln y +\frac{dy}{dx}\times \frac{x}{y})y^x$$ So $$\frac{dy}{dx}x^y\ln x +yx^{y-1}=\frac{dy}{dx}xy^{x-1}+y^x \ln y$$ Extensively rearranging gives: $$\frac{dy}{dx}=\frac{y^x \ln y -yx^{y-1}}{x^y \ln x -xy^{x-1}}$$ Let $\frac{dy}{dx}=-1$: $$y^x \ln y -yx^{y-1}=xy^{x-1}-x^y\ln x$$ But we know $x=y$ since we are at the intersection point with the line $y=x$: $$x^x \ln x -x^x=x^x-x^x\ln x$$ So $2x^x \ln x -2x^x=0$ $$2x^x(\ln x -1)=0$$ This means either $2x^x=0$ or $\ln x -1=0$ but we know $x^x$ is always greater than $0$ so $\ln x =1$, leaving us with: $$x=y=e$$ So I have my answer, but is there any other method of getting it? I have heard there is. Any help will be very welcome. Thanks in advance Non-Metrizable Topological Spaces How are pronouns resolved? Are pronouns in English resolved syntactically or semantically? Do they always refer to the closest matching noun?  A  has these examples:        We gave the bananas to the monkeys because they were hungry.   We gave the bananas to the monkeys because they were ripe.   We gave the bananas to the monkeys because they were here.       My understanding was that pronouns are resolved syntactically, and so sentence 2 is semantically incorrect (unless the author really meant that the monkeys were ripe) and sentence 3 is not ambiguous. Is this wrong?  Citations and references are most welcome. How does a USB 2.0 Wall Charger negotiate current output? I'm trying to use a mobile phone charger for my projects, and want a high current output. I have read , however my measurements show something else.  is a link to the Battery Charging Specification Rev. 1.2.  1.4.7 Dedicated Charging Port A Dedicated Charging Port (DCP) is a downstream port on a device that outputs power through a USB connector, but is not capable of enumerating a downstream device. A DCP shall source \$I_{DCP}\$ at an average voltage of \$V_{CHG}\$. A DCP shall short the D+ line to the D- line.   I verified on three different chargers, and all read \$R_{DCP\_DAT}\$ as ~1.5 Ohms. Now, if there is a short between the D+ and D-, there is no detection on the charging port side, and the charger should always output \$I_{DCP}\$ {0.5 - 5.0A max} on the VBUS line - is this correct? I tested the current output of three chargers, but they are all completely different. Charger 1 - Nokia Rated current output: 1.3A Measured current output: 1.34A Charger 2 - Asus Rated current output: 2.0A Measured current output: 0.7A - 1.1A (unstable) Charger 3 - HTC Rated current output: 1A Measurent current output: 0.1A If all these dedicated charging ports have no current negotiation, how come only one charger is showing it's rated output? N.B All three chargers can charge a mobile phone in a reasonable amount of time. Uncertainty and wave-trains My textbook and the following extract from feynman's lectures present the same idea regarding wavetrains and uncertainty in their wavelengths. Why is it that a wavetrain confined to some space has an uncertainty in its wavelength or the wave number? Is not a confined wave-train equivalent to a burst of successive pulses which can have a definite wavelength according to their origin or nature of origin.   Next, i understand that the De Broglie relation relates the uncertainty in wavelength to the uncertainty in momentum but what links the finiteness of the wave-train to the uncertainty in position? How can I ensure my Samsung Series 7 is actually using the Radeon switchable graphics? I have a Samsung Series 7 with the Radeon 6750M switchable graphics. The ATI software lets you force programs to use the dedicated card. However, I'm not convinced it is actually ever using it, as the frame rates on some non-taxing games (Portal, TF2) are merely OK. To make matters worse, it looks like the ATI Catalyst Control has vanished from my laptop. To make it even worse, you can't download the driver and ATI CCC from ATI's site, you need to download it from Samsung, and the ZIP they provide is corrupted.   How can I ensure my Samsung Series 7 is actually using the Radeon switchable graphics? What is the integral of 1/x? What is the integral of $\frac{1}{x}$? Do you get $\ln(x)$ or $\ln|x|$? In general, does integrating $f'(x)/f(x)$ give $\ln(f(x))$ or $\ln|f(x)|$? Also, what is the derivative of $|f(x)|$? Is it $f'(x)$ or $|f'(x)|$? I've been very into acoustics lately, specifically the harmonic series. I find it fascinating how the harmonic series works as a sort of guideline to harmony, and how we base tuning systems on trying to estimate the intervals from the harmonic series.  As you've probably gathered already, I know close to nothing about acoustics. But I would love an acoustic textbook that's suitable for dummies like myself. Probability of $p(x_1<x_2<\max(x_3,x_4))$ Should we sign-then-encrypt, or encrypt-then-sign? How to prove that $p-1$ is squarefree infinitely often, where $p$ is prime?  I had thought of using Dirichlet's theorem on arithmetic progressions.  The number of squareful values of $p-1$ less than or equal to $n$ is bounded by $\sum_{q}{\pi_{q^2,1}(n)}$, each term $\pi_{q^2,1}(n) \approx \frac{\pi(n)}{q \cdot (q-1)}$, and $\sum_{q}{\frac{1}{q \cdot (q-1)}} \lt 1$.  But using for example , the possibility is open that the error in each approximation for $\pi_{q^2,1}(n)$ may continue to increase with $q$, and since the sum runs up to $\sqrt{n}$, this argument is invalid.  Is there a more refined version of Dirichlet's theorem that can be used to circumvent this issue?  Or an entirely different way to prove this statement? Ubuntu 14.04: very slow UI in Oracle VirtualBox Short summary: 14.04 is much slower than 12.04 even with more RAM assigned.  I'm using latest VirtualBox 4.3.10 on Mavericks 10.9.2. How can I make it faster? Is there a limit as to how fast a black hole can grow? As I understand it, there are several models for what the universe could look like from the “outside”. I don’t know if any of these are outdated, so if they are please tell me if they are.   Expanding bubble. This model says the universe will never stop expanding, and the universe will die because the energy all turns to photons and gets spread out so much. Bubble that will eventually collapse. In this model the universe will stop expanding, and collapse. Everything merges into super-massive black holes, and the universe dies with fire. The universe is a torus. I'm not clear whether the size of the universe in this model is changing, but the central idea is that space is donut-shaped.   Those are the major ones that I have heard of. My question involves what I have heard to be the most popular of the three, #2. In this model, eventually something will "touch" the edge of the universe. Obviously, the first thing to "touch" it would be photons as they travel at, well, the speed of light. This involves all forms of energy in the universe, but I thought it might be easier to explain for something without mass.  What happens if some form of energy "touches" the edge of the universe? Logically, the energy cannot be lost without violating the law of conservation of energy. The only thing I can think of, is that it would "bounce" or be refracted off the edge.  I realize that it sounds silly, however if model #2 is correct then this situation will arise some number of billions of years from now.  I can only assume that there is either a new model that accounts for this, there is some complex explanation, or that model #2 is incorrect. What is a tensor? I have a pretty good knowledge of physics, but couldn't deeply understand what a  is and why it is so fundamental. Saleforce Too many future calls: 11