Re: Multi-threaded help
Re: Multi-threaded help
- Subject: Re: Multi-threaded help
- From: Dave Camp <email@hidden>
- Date: Fri, 9 Mar 2007 15:09:47 -0800
On Mar 9, 2007, at 11:59 AM, Jan Erik Breimo wrote:
Den 9. mar. 2007 kl. 01.43 skrev arri:
On Mar 7, 2007, at 16:41 19, Erik Buck wrote:
.. it is nearly impossible to create non-trivial multi-threaded
programs that are correct.
but why?
While he probably isn't, he might be alluding to the fact that C
(at least not until the most recent standard) and C++ don't really
support multi-threading. When you control access to some shared
resource by locking a mutex or some equivalent, there's no way to
specify within the standard languages that the lock-function is
special and that an optimizing compiler isn't allowed to reorganize
the code so that instructions originally appearing after the lock
are actually executed before it. gcc probably has some compiler
specific keyword that really makes this a non-issue in Cocoa, but
it might at least be a minor concern for someone writing cross-
platform code.
Mmm. No. If that were true, most of the threaded code in the world
would simply not work. The compiler can't just change the order of
execution of calls to functions like [NSLock lock] or
pthread_mutex_lock(). You don't need to do anything special to get
locks and semaphores to work as expected. If your threading model is
not working it's most likely due to a design flaw in your software,
not the compiler.
For anyone delving into threads for the first time, I'd highly
recommend the Pthreads Programmng book from OReilly. It's a good read
regardless of the language or framework you are using.
Dave
---
In English, every word can be verbed.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden