RE: Is there only one CFRunLoopRun which can implement in one process
RE: Is there only one CFRunLoopRun which can implement in one process
- Subject: RE: Is there only one CFRunLoopRun which can implement in one process
- From: Chris Gardner <email@hidden>
- Date: Sun, 17 May 2009 20:26:02 +0800
- Importance: Normal
Hi Ken,
Thanks for your reply.
You are right, there are other API build on top of a run loop.
In main thread, I create a thread function in which I implement a class instance that can download file.
The question is that after the first thread downloaded file , the second the thread will begin downloading file. That said,
the first CFRunLoopRun will block the secord CFRunLoopRun.
The main framework show below:
in MainController.m:
@implementation MainController
....
[NSThread detachNewThreadSelector selector(TransferDownloadThreadProc:) toTarget elf withObject id)vAllParam];
....
- (void) TransferDownloadThreadProc:(id)userInfo
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
...
Transfer * download = [[Transfer alloc] init]; // Transfer class is customed by myself
[download InitTransferParam:url
withLocalFolder: strLocalFolder
withUserName: strUsername
withPassword: strPassword];
[download StartupDownload];
[NSThread exit];
[pool release];
}
....
in Transfer.m
static void DownloadCallBack(CFReadStreamRef readStream, CFStreamEventType type, void * clientCallBackInfo)
{
....
}
@implementation Transfer
....
- (Boolean)TransferDownload CFStringRef)urlString DstFolder CFURLRef)destinationFolder Username CFStringRef)user Password CFStringRef)pwd
{
...
CFReadStreamSetClient(readStream, kNetworkEvents, DownloadCallBack, &context);
CFReadStreamScheduleWithRunLoop(readStream, CFRunLoopGetCurrent(), kCFRunLoopCommonModes);
...
}
- (void)StartupDownload
{
....
CFRunLoopRun();
....
}
....
Regard,
Chris Wu
> From: email@hidden
> To: email@hidden
> Date: Sun, 17 May 2009 06:53:44 -0500
> CC: email@hidden
> Subject: Re: Is there only one CFRunLoopRun which can implement in one process
>
> On May 17, 2009, at 12:04 AM, Chris Gardner wrote:
>
> > I have created two thread, and in each thread I call CFRunLoopRun
> > function to download file from FTP server.
>
> It should not be necessary to create two threads. The whole point of
> run loops is that they manage multiple asynchronous input sources,
> allowing your program to process events from any of them as they
> occur. It should be possible to manage multiple simultaneous FTP
> downloads at once from your program's main thread.
>
> That said, what API are you using to perform the FTP downloads?
> Running the run loop is part of the basic infrastructure. It doesn't
> have anything to do with FTP downloads, specifically. You must be
> using some other API built on top of a run loop, right? It may be
> best to show your code.
>
>
> > Can the CFRunLoopRun function implement in two PROCESS, but not in
> > two THREAD.
>
> It is possible to have two threads within the same process, each
> running their own run loop. The two will run independently and are
> capable of processing input sources simultaneously.
>
> If you're seeing your FTP downloads being serialized, then it's due to
> something else. The problem isn't a limitation of run loops.
>
> Regards,
> Ken
>
> _______________________________________________
>
> Cocoa-dev mailing list (email@hidden)
>
> Please 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
_________________________________________________________________
More than messages–check out the rest of the Windows Live™.
http://www.microsoft.com/windows/windowslive/_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please 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