Re: Messages between Threads

2009-03-16 Thread Michael Ash
On Mon, Mar 16, 2009 at 1:43 AM, Gerriet M. Denkmann wrote: > > On 15 Mar 2009, at 15:43, Joar Wingfors wrote: >> >> On 15 mar 2009, at 01.14, Paul Sanders wrote: >> >>> I was referring to where the OP said: >>> "but would it be safe, given the fact that sum and count are bound to some

Re: Messages between Threads

2009-03-16 Thread Michael Vannorsdel
You'll need to use an atomic operation to access tempSum in the main thread as well and make sure tempSum is on a 4 byte boundary (required by atomic ops). But a cleaner method would be to keep a local running total in the worker thread and after your time period send a message to the main

Re: Messages between Threads

2009-03-16 Thread Chris Hanson
On Mar 15, 2009, at 10:43 PM, Gerriet M. Denkmann wrote: On 15 Mar 2009, at 15:43, Joar Wingfors wrote: Please refer to the Cocoa thread safety documentations:

Re: Messages between Threads

2009-03-15 Thread Gerriet M. Denkmann
On 15 Mar 2009, at 15:43, Joar Wingfors wrote: On 15 mar 2009, at 01.14, Paul Sanders wrote: I was referring to where the OP said: "but would it be safe, given the fact that sum and count are bound to some textFields / progressIndicator" And presumably it would not be as the instance var

Re: Messages between Threads

2009-03-15 Thread Michael Ash
On Sun, Mar 15, 2009 at 10:34 AM, Shawn Erickson wrote: > On Sun, Mar 15, 2009 at 1:40 AM, Paul Sanders wrote: I am used to a more robust threading model. >> >>> I'm curious, what is not "robust" about the Cocoa threading model, and >>> what are you comparing it to? >> >> Well, only being ab

Re: Messages between Threads

2009-03-15 Thread Shawn Erickson
On Sun, Mar 15, 2009 at 1:40 AM, Paul Sanders wrote: >>> I am used to a more robust threading model. > >> I'm curious, what is not "robust" about the Cocoa threading model, and >> what are you comparing it to? > > Well, only being able to draw and process events on the main thread mainly. You can

Re: Messages between Threads

2009-03-15 Thread Paul Sanders
>> I am used to a more robust threading model. > I'm curious, what is not "robust" about the Cocoa threading model, and > what are you comparing it to? Well, only being able to draw and process events on the main thread mainly. I am comparing it to Windows where a secondary thread can do what it

Re: Messages between Threads

2009-03-15 Thread Joar Wingfors
On 15 mar 2009, at 01.14, Paul Sanders wrote: I was referring to where the OP said: "but would it be safe, given the fact that sum and count are bound to some textFields / progressIndicator" And presumably it would not be as the instance variables referred to were being mutated in a seco

Re: Messages between Threads

2009-03-15 Thread Paul Sanders
> Rather than doing it every 1000 iterations, make it be time-based. Yes, I agree with you there. That's what I myself usually do in fact. > I'm not sure what you're referring to when you talk about "other > techniques", but in general it is forbidden to access the GUI of a > Cocoa app from seco

Re: Messages between Threads

2009-03-14 Thread Michael Ash
On Sat, Mar 14, 2009 at 1:29 PM, Paul Sanders wrote: >> So: what should be done? > > 1.  Do the calculations in a sub-thread. > > 2.  Test a 'please stop' variable each time round the loop in that thread. > > 3.  Set this variable in the main thread when the user clicks the Stop > button. Better

Re: Messages between Threads

2009-03-14 Thread Paul Sanders
> So: what should be done? 1. Do the calculations in a sub-thread. 2. Test a 'please stop' variable each time round the loop in that thread. 3. Set this variable in the main thread when the user clicks the Stop button. 4. To show progress, call performSelectorOnMainThread from the sub-thre

Messages between Threads

2009-03-14 Thread Gerriet M. Denkmann
I have a Main object which has: - (void)add2Number: (NSNumber *)n; { self.sum += [ n intValue ];;// bound to TextField self.count++; // bound to TextField and ProgressIndicator } The UserInterface has a Start/Stop button which does (on St