bugGNUstep - Bugs: bug #39107, NSRunLoop and input source bug

 
 

You are not allowed to post comments on this tracker with your current authentification level.

bug #39107: NSRunLoop and input source bug

Submitted by:  Cameron Pulsford <cpulsford>
Submitted on:  Tue 28 May 2013 06:47:17 PM UTC  
 
Category: Base/FoundationSeverity: 3 - Normal
Item Group: BugStatus: None
Privacy: PublicAssigned to: None
Open/Closed: Open

Tue 28 May 2013 06:47:17 PM UTC, original submission:

Hardware: Intel celeron, 4gb ram, (Intel NUC)
Software: Debian wheezy, gnustep-base 1.24.4 build with GCC 4.7.2.

The attached project is a simplified version of some code I am having issues with.

The code runs the run loop on the main thread while scheduling timers also on the main thread. I am thinking that the performSelector:onThread:withObject:waitUntilDone: method counts as an input source on the mac and not under GNUstep?

Since the Apple recommended way to run a run loop while waiting for a certain condition is as follows:

while (!condition) {
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]];
}

it makes it difficult to write correct code when the -runMode:beforeDate: method is returning YES BEFORE the event that caused it to return is processed.

Here is the output when run on my mac in a test xcode project (this output stays consistent across all variations that are presented):

2013-05-28 14:04:50.151 Untitled[36450:707] CBP____ scheduling the timer
2013-05-28 14:04:50.152 Untitled[36450:707] CBP____ run loop
2013-05-28 14:04:50.153 Untitled[36450:707] CBP____ run loop
2013-05-28 14:04:51.153 Untitled[36450:707] CBP____ rescheduling the timer
2013-05-28 14:04:51.155 Untitled[36450:707] CBP____ scheduling the timer
2013-05-28 14:04:51.157 Untitled[36450:707] CBP____ run loop
2013-05-28 14:04:52.158 Untitled[36450:707] CBP____ rescheduling the timer
2013-05-28 14:04:52.160 Untitled[36450:707] CBP____ scheduling the timer
2013-05-28 14:04:52.160 Untitled[36450:707] CBP____ run loop
2013-05-28 14:04:53.161 Untitled[36450:707] CBP____ rescheduling the timer
2013-05-28 14:04:53.163 Untitled[36450:707] CBP____ scheduling the timer
2013-05-28 14:04:53.164 Untitled[36450:707] CBP____ run loop

Here is the output when compiled and run on my debian system:

2013-05-28 14:20:38.188 test[15647] CBP____ scheduling the timer
2013-05-28 14:20:38.190 test[15647] CBP____ run loop
2013-05-28 14:20:39.191 test[15647] CBP____ run loop
2013-05-28 14:20:39.191 test[15647] CBP____ rescheduling the timer
2013-05-28 14:20:39.191 test[15647] CBP____ run loop
2013-05-28 14:20:39.191 test[15647] CBP____ run loop
2013-05-28 14:20:39.192 test[15647] CBP____ run loop
2013-05-28 14:20:39.192 test[15647] CBP____ run loop
2013-05-28 14:20:39.192 test[15647] CBP____ run loop
2013-05-28 14:20:39.192 test[15647] CBP____ run loop
2013-05-28 14:20:39.192 test[15647] CBP____ run loop
2013-05-28 14:20:39.192 test[15647] CBP____ run loop
2013-05-28 14:20:39.193 test[15647] CBP____ run loop
2013-05-28 14:20:39.193 test[15647] CBP____ run loop
... infinitely

If I add a bogus input source by adding the following line above the "while (YES)" line of code,

[[NSRunLoop currentRunLoop] addPort:[NSPort port] forMode:NSDefaultRunLoopMode];

I get the following output on my debian system (notice the 30 second delays in the timing).

2013-05-28 14:26:05.827 test[15704] CBP____ scheduling the timer
2013-05-28 14:26:05.828 test[15704] CBP____ run loop

2013-05-28 14:26:06.830 test[15704] CBP____ run loop
2013-05-28 14:26:06.830 test[15704] CBP____ rescheduling the timer
2013-05-28 14:26:06.830 test[15704] CBP____ scheduling the timer

2013-05-28 14:26:35.835 test[15704] CBP____ run loop
2013-05-28 14:26:35.836 test[15704] CBP____ rescheduling the timer
2013-05-28 14:26:35.836 test[15704] CBP____ scheduling the timer

2013-05-28 14:27:05.859 test[15704] CBP____ run loop
2013-05-28 14:27:05.859 test[15704] CBP____ rescheduling the timer
2013-05-28 14:27:05.859 test[15704] CBP____ scheduling the timer

The "CBP____ run loop" log also looks out of order, I would expect to see that AFTER the rescheduling logs.

If I then make the following change to -rescheduleTimer and add the -threadTest method I get different output again on the debian system but not on the mac.

- (void)rescheduleTimer:(NSTimer *)timer
{
NSLog(@"CBP____ rescheduling the timer");
[NSThread detachNewThreadSelector:@selector(threadTest) toTarget:self withObject:nil];
}

- (void)threadTest
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

[self performSelectorOnMainThread:@selector(scheduleTimer) withObject:nil waitUntilDone:NO];

[pool release];
}

2013-05-28 14:35:33.764 test[15844] CBP____ scheduling the timer
2013-05-28 14:35:33.766 test[15844] CBP____ run loop
2013-05-28 14:35:34.766 test[15844] CBP____ run loop
2013-05-28 14:35:34.766 test[15844] CBP____ rescheduling the timer
2013-05-28 14:35:34.767 test[15844] CBP____ scheduling the timer
2013-05-28 14:35:34.767 test[15844] CBP____ run loop

2013-05-28 14:35:35.769 test[15844] CBP____ run loop
2013-05-28 14:35:35.769 test[15844] CBP____ rescheduling the timer
2013-05-28 14:35:35.770 test[15844] CBP____ scheduling the timer
2013-05-28 14:35:35.770 test[15844] CBP____ run loop

2013-05-28 14:35:36.771 test[15844] CBP____ run loop
2013-05-28 14:35:36.771 test[15844] CBP____ rescheduling the timer
2013-05-28 14:35:36.772 test[15844] CBP____ scheduling the timer
2013-05-28 14:35:36.772 test[15844] CBP____ run loop

Cameron Pulsford <cpulsford>

 

Attached Files
file #28200:  RunLoopTest.zip added by cpulsford (2kB - application/zip)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -unavailable- added by FredKiefer (Updated the item)
  • -unavailable- added by cpulsford (Submitted the item)
  •  

    Do you think this task is very important?
    If so, you can click here to add your encouragement to it.
    This task has 0 encouragements so far.

    Only logged-in users can vote.

     

    Please enter the title of George Orwell's famous dystopian book (it's a date):

     

     

    Follow 3 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Sat 07 Dec 2013 08:57:59 PM UTCFredKieferCategoryNone=>Base/Foundation
      Item GroupNone=>Bug
    Tue 28 May 2013 06:47:17 PM UTCcpulsfordAttached File-=>Added RunLoopTest.zip, #28200

    Back to the top


    Powered by Savane 3.1-cleanup