elegos wrote:
Second: AFAIK the @syncronized block of code forces all the threads to wait it, am I right?
Yes. Use them sparingly.
My environment readings take some milliseconds and repeat each second, they may affect the general performance.
You only need the @synchronized block to provide mutual exclusion with your shared variables. Your thread can take as long as it needs to gather the readings, but when it goes to store them in the shared variable, that is when it should use the @synchronized block.
I don't know what is taking place that would take milliseconds to "gather the readings". If you have some external data source, you may need yet another thread just to read data from that source. I don't know the details. Having updates once per second is no big deal. In any event, this is the simplest mechanism. Start with it and see how it works. If you find need something better, at least you are starting from a working, albeit slow, system instead of from zero.
For the NSThread: I must create an NSAutoreleasePool, am I right?
Yes.
Also, the readings are made by other classes than the main one. AFAIK I can't use them in another thread than the one I'm running them (I should initialize a new instance of them),
I don't know exactly what you mean by "readings". If, for example, you had data coming in over a relatively slow USB or wireless link, you may need a separate thread just to handle that data. I don't know. If your data was coming in over a remote TCP/IP or distributed objects link, then that can be handled in the main thread.
how can I wrap their variables into an NSDictionary continuously? Global variables? How can I use them?
Yes, they are global, or maybe static, variables. If you only need to maintain the latest reading, you can use a dictionary to key each individual reading with each latest value. If you need to track all values, you may need an array - or perhaps your dictionary value is an NSArray. If you put everything you need to share into one dictionary, you can easily perform the @synchronized directive against that dictionary.
Why system monitor says my application is using one thread, even if I enter an infinite loop within a new thread? Shouldn't it count as 2-threads application?
I don't know. Perhaps system monitor only counts the number of NSRunLoops. Almost any Cocoa program I've seen has at least 3 threads just to start with.