• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
thread spinning ...
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

thread spinning ...


  • Subject: thread spinning ...
  • From: Martin Redington <email@hidden>
  • Date: Wed, 6 Dec 2006 04:21:38 +0000


Please remind me never to do any multi-threaded programming again.

I have a loop that drives my worker thread, that looks something like the code below. Recently, I've observed one of these threads (occasionally more, but usually just one), "spinning" in this loop, and consuming a lot of CPU. I'm pretty certain that at the time, the thread is not receiving any messages, just waiting around to be reaped. Normally, this code runs without incident.

// threadRunning is a utility method that checks the threadDictionary to see if a flag has been set.
// it is only set or accessed from within the current thread.


while ([self threadRunning])
{
NSDate *newDate = [[NSDate alloc] initWithTimeIntervalSinceNow: 0.50];
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:newDate];
[newDate release];
}


When I sample the app in this "spinning" state, I get a trace like the one below. I've got quite a few, and they all have this characteristic appearance, and seem to be stuck in this same region of code.



============================================================

248 Thread_1403
248 _pthread_body
248 forkThreadForFunction
213 +[MMIUtils(MultiThreadingPrivate) performSelectorInNewThread:]
66 -[NSRunLoop runMode:beforeDate:]
44 _CFRunLoopFinished
35 __CFRunLoopFindMode
35 CFSetGetValue
31 __CFSetFindBuckets1b
16 CFEqual
14 __CFRunLoopModeEqual
14 CFEqual
12 __CFStringEqual
12 __CFStringEqual
2 CFEqual
2 CFEqual
12 __CFStringHash
12 __CFStringHash
3 __CFSetFindBuckets1b
3 CFSetGetValue
1 __CFStringHash
1 __CFStringHash
5 __spin_lock
5 __spin_lock
2 __CFRunLoopModeIsEmpty
1 CFSetGetCount
1 CFSetGetCount
1 __CFRunLoopModeIsEmpty
1 0xa0810050
1 0xa0810050
1 CFSetGetValue
1 CFSetGetValue
7 -[NSCFString isEqual:]
4 -[NSCFString isEqual:]
3 -[NSObject isKindOfClass:]
3 -[NSObject isKindOfClass:]
6 CFEqual
5 __CFStringEqual
5 __CFStringEqual
1 CFEqual
3 __i686.get_pc_thunk.bx
3 __i686.get_pc_thunk.bx
2 __spin_lock
2 __spin_lock
2 objc_msgSend
2 objc_msgSend
1 -[NSRunLoop runMode:beforeDate:]
1 CFRunLoopGetCurrent
1 CFRunLoopGetCurrent
37 -[NSCFDate initWithTimeIntervalSinceReferenceDate:]
18 NSDeallocateObject
16 _internal_object_dispose
16 free
7 szone_free
7 szone_free
3 0xa0011113
3 0xa0011113
3 szone_size
3 szone_size
2 __spin_lock
2 __spin_lock
1 free
1 NSDeallocateObject
1 free
1 free
17 CFDateCreate
11 _CFRuntimeCreateInstance
6 malloc_zone_malloc
2 __spin_lock
2 __spin_lock
2 malloc_zone_malloc
1 __i686.get_pc_thunk.bx
1 __i686.get_pc_thunk.bx
1 szone_malloc
1 szone_malloc
2 CFAllocatorAllocate
2 CFAllocatorAllocate
2 _CFRuntimeCreateInstance
1 __i686.get_pc_thunk.bx
1 __i686.get_pc_thunk.bx
4 pthread_getspecific
4 pthread_getspecific
2 CFDateCreate
2 _internal_object_dispose
2 _internal_object_dispose
33 +[MMIUtils(MultiThreading) threadRunning]
29 CFDictionaryGetValue
23 __CFDictionaryFindBuckets1b
13 CFEqual
9 __CFStringEqual
9 __CFStringEqual
4 CFEqual
5 __CFStringHash
5 __CFStringHash
2 CFHash
2 CFHash
2 __CFDictionaryFindBuckets1b
1 __i686.get_pc_thunk.bx
1 __i686.get_pc_thunk.bx
5 CFDictionaryGetValue
1 __CFStringHash
1 __CFStringHash
2 -[NSThread threadDictionary]
2 -[NSThread threadDictionary]
1 _NSCurrentThread
1 _NSCurrentThread
1 __i686.get_pc_thunk.bx
1 __i686.get_pc_thunk.bx
20 +[NSObject alloc]
9 NSAllocateObject
5 _internal_class_createInstanceFromZone
3 object_cxxConstructFromClass
2 object_cxxConstructFromClass
1 __i686.get_pc_thunk.bx
1 __i686.get_pc_thunk.bx
1 object_cxxConstructFromClass
1 object_cxxConstructFromClass
1 object_cxxConstructFromClass
1 __i686.get_pc_thunk.bx
1 __i686.get_pc_thunk.bx
2 malloc_zone_calloc
2 szone_calloc
2 __bzero
2 __bzero
3 NSAllocateObject
1 0xa0a67028
1 0xa0a67028
6 +[NSDate allocWithZone:]
6 +[NSDate allocWithZone:]
4 objc_msgSend
4 objc_msgSend
1 _internal_class_createInstanceFromZone
1 _internal_class_createInstanceFromZone
16 -[NSDate initWithTimeIntervalSinceNow:]
10 CFAbsoluteTimeGetCurrent
9 gettimeofday
9 __gettimeofday
5 __gettimeofday
4 __nanotime
4 __nanotime
1 __commpage_gettimeofday
1 __commpage_gettimeofday
5 -[NSDate initWithTimeIntervalSinceNow:]
1 0xa08103c0
1 0xa08103c0
16 objc_msgSend
16 objc_msgSend
15 _CFRelease
9 szone_free
9 szone_free
2 CFAllocatorDeallocate
2 CFAllocatorDeallocate
1 _CFRelease
1 __spin_lock
1 __spin_lock
1 malloc_zone_free
1 malloc_zone_free
1 spin_lock
1 spin_lock
3 +[NSRunLoop currentRunLoop]
1 -[NSThread runLoop]
1 -[NSThread runLoop]
1 0xa26213bb
1 0xa26213bb
1 _NSCurrentThread
1 _NSCurrentThread
1 -[NSCFBoolean boolValue]
1 CFBooleanGetValue
1 CFBooleanGetValue
1 -[NSCFString isEqual:]
1 -[NSCFString isEqual:]
1 0xa262104b
1 0xa262104b
1 0xdc028
1 0xdc028
1 CFBooleanGetValue
1 CFBooleanGetValue
1 CFRelease
1 CFRelease
1 __i686.get_pc_thunk.bx
1 __i686.get_pc_thunk.bx
27 objc_msgSend
27 objc_msgSend
4 CFMakeCollectable
4 CFMakeCollectable
1 -[NSCFBoolean boolValue]
1 -[NSCFBoolean boolValue]
1 -[NSCFDate release]
1 -[NSCFDate release]
1 0xdc028
1 0xdc028
1 CFRelease
1 CFRelease




_______________________________________________

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


  • Follow-Ups:
    • Re: thread spinning ...
      • From: Shawn Erickson <email@hidden>
    • Re: thread spinning ...
      • From: Chris Suter <email@hidden>
  • Prev by Date: Re: 10.4 date format help
  • Next by Date: Re: thread spinning ...
  • Previous by thread: Re: Framework for displaying Trees graphically?
  • Next by thread: Re: thread spinning ...
  • Index(es):
    • Date
    • Thread