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

Group
 
 

bug #39107: NSRunLoop and input source bug

Submitter:  Cameron Pulsford <cpulsford>
Submitted:  Tue 28 May 2013 06:47:17 PM UTC
   
 
Category:  Base/Foundation Severity:  3 - Normal
Item Group:  Bug Status:  Fixed
Privacy:  Public Assigned to:  None
Open/Closed:  In Test
* Mandatory Fields

Add a New Comment Rich Markup
   

Mon 14 Jul 2014 08:25:35 AM UTC, comment #1: 

I've added a check for performers in -runMode:beforeDate: in svn trunk.
Does that do the right thing to mimic OSX behavior?

Richard Frith-Macdonald <CaS>
Group Member
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>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

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

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by CaS (Posted a comment)
  • -email is unavailable- added by FredKiefer (Updated the item)
  • -email is unavailable- added by cpulsford (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.

     

    Follow 5 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2014-07-14 CaS StatusNone Fixed
        Open/ClosedOpen In Test
    2013-12-07 FredKiefer CategoryNone Base/Foundation
        Item GroupNone Bug
    2013-05-28 cpulsford Attached File- Added RunLoopTest.zip, #28200

    Back to the top

    Powered by Savane 3.13-3230.
    Corresponding source code