• 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
URL loading system not threadsafe?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

URL loading system not threadsafe?


  • Subject: URL loading system not threadsafe?
  • From: Henk Kampman <email@hidden>
  • Date: Fri, 18 Nov 2005 14:33:31 +0100

The following code always crashes in NSURLCache (see partial crashlogs) after running for a few minutes.
It looks as if the default NSURLCache mechanism is broken or not threadsave, is this correct or am I doing something wrong?



Henk

BTW I'm using a G5 DP2.0 running OSX 10.4.3


#import "MainController.h"

@implementation MainController

- (void)applicationDidFinishLaunching:(NSNotification *)notification
{
// spawn 8 threads
[NSThread detachNewThreadSelector:@selector(testThread:) toTarget:self withObject:nil];
[NSThread detachNewThreadSelector:@selector(testThread:) toTarget:self withObject:nil];
[NSThread detachNewThreadSelector:@selector(testThread:) toTarget:self withObject:nil];
[NSThread detachNewThreadSelector:@selector(testThread:) toTarget:self withObject:nil];
[NSThread detachNewThreadSelector:@selector(testThread:) toTarget:self withObject:nil];
[NSThread detachNewThreadSelector:@selector(testThread:) toTarget:self withObject:nil];
[NSThread detachNewThreadSelector:@selector(testThread:) toTarget:self withObject:nil];
[NSThread detachNewThreadSelector:@selector(testThread:) toTarget:self withObject:nil];
}


- (void)testThread:(id)anObject
{
	NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

	NSURL* url = [NSURL URLWithString: @"http://www.apple.com/";];

	 while(1)
	 {
		NSAutoreleasePool *innerPool = [[NSAutoreleasePool alloc] init];

		NS_DURING

		NSData* receivedData = [NSData dataWithContentsOfURL:url];

		if(receivedData == NULL)
		{
			NSLog(@"timeout");
		}

		NS_HANDLER
			NSLog(@"exception");
		NS_ENDHANDLER

		[innerPool release];
	 }

	 [pool release];
}

@end



_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: URL loading system not threadsafe?
      • From: Jerry Krinock <email@hidden>
  • Prev by Date: Re: Automagic instantiation of singletons?
  • Next by Date: the right place where put a serial number
  • Previous by thread: Re: App window remaining invisible after maximize from Dock(CORRECTIONS)
  • Next by thread: Re: URL loading system not threadsafe?
  • Index(es):
    • Date
    • Thread