1 #import "AppDelegate.h"2 3 @interfaceappdelegate ()4 5 @end6 7 @implementationappdelegate8 9-(void) dealloc{Ten One [_window release]; A [Super Dealloc]; - } - the --(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (Nsdictionary *) launchoptions { -Self.window =[[UIWindow alloc]initwithframe:[uiscreen mainscreen].bounds]; -Self.window.backgroundColor =[Uicolor Blackcolor]; + - [Self.window makekeyandvisible]; + A [_window release]; at - //thread mutexes do not have their own independent stack space, all using the internal memory space of the process, so it is possible that multiple threads access the same piece of memory at the same time, there will be problems, access to the shared resources for multi-threaded is a thread mutex, add the line lock -Nslock *lk =[[Nslock alloc]init]; - -Nsthread *thread1 = [[Nsthread alloc]initwithtarget:self selector: @selector (Therad:)Object: LK]; - inThread1.name =@"Window No. 1th"; - to [thread1 start]; + - the *Nsthread *therad2 = [[Nsthread alloc]initwithtarget:self selector: @selector (Therad:)Object: LK]; $ Panax NotoginsengTherad2.name =@"window No. 2nd" ; - the //therad2.threadpriority = 0.9; + A [therad2 start]; the + - $Nsthread *therad3 = [[Nsthread alloc]initwithtarget:self selector: @selector (Therad:)Object: LK]; $ -Therad3.name =@"Window No. 3rd" ; - theTherad3.threadpriority =1 ; - Wuyi [therad3 start]; the - Wu - About $ - returnYES; - } - A + //Mock Ticketing the-(void) Therad: (ID)Object{ - $Nslock *lk = (Nslock *)Object ; the the //number of votes 100 sheets the Static intNumber = - ; the - while(1) { in the //Add line lock to improve security of data access the[LKLock]; About theNumber-- ; the theNSLog (@"%@%d", [[Nsthread currentthread]name],number]; + - //Sleep 1 seconds theSleep1);Bayi the if(Number = =0) { the Break ; - } - the [lk unlock]; the } the the}
Nslock Simple Application