bug-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[bug #39107] NSRunLoop and input source bug


From: Cameron Pulsford
Subject: [bug #39107] NSRunLoop and input source bug
Date: Tue, 28 May 2013 18:47:18 +0000
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_4) AppleWebKit/536.30.1 (KHTML, like Gecko) Version/6.0.5 Safari/536.30.1

URL:
  <http://savannah.gnu.org/bugs/?39107>

                 Summary: NSRunLoop and input source bug
                 Project: GNUstep
            Submitted by: cpulsford
            Submitted on: Tue 28 May 2013 06:47:17 PM GMT
                Category: None
                Severity: 3 - Normal
              Item Group: None
                  Status: None
                 Privacy: Public
             Assigned to: None
             Open/Closed: Open
         Discussion Lock: Any

    _______________________________________________________

Details:

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




    _______________________________________________________

File Attachments:


-------------------------------------------------------
Date: Tue 28 May 2013 06:47:17 PM GMT  Name: RunLoopTest.zip  Size: 2kB   By:
cpulsford

<http://savannah.gnu.org/bugs/download.php?file_id=28200>

    _______________________________________________________

Reply to this item at:

  <http://savannah.gnu.org/bugs/?39107>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.gnu.org/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]