Re: OS/X Java native bug
Re: OS/X Java native bug
- Subject: Re: OS/X Java native bug
- From: Michael Hall via Cocoa-dev <email@hidden>
- Date: Fri, 17 Mar 2023 06:51:27 -0500
> On Mar 17, 2023, at 6:31 AM, Michael Hall <email@hidden> wrote:
>
>
>
>> On Mar 17, 2023, at 4:07 AM, Saagar Jha <email@hidden> wrote:
>>
>> The implementation of -[ThreadUtilities performOnMainThreadWaiting:block:]
>> does the right thing here, which is calling the block directly if it’s
>> already running on the main thread:
>> https://github.com/openjdk/jdk/blob/9d518c528b11953b556aa7585fc69ff9c9a22435/src/java.desktop/macosx/native/libosxapp/ThreadUtilities.m#L103.
>> It’s likely that your hang is caused by something else.
>>
>> Saagar Jha
>>
>
> That was already suggested but I couldn’t understand how it could be done.
> I’ll take it as correct with the second opinion. The stack trace seemed to
> indicate this as the place. Maybe something within the block.
> I may have to debug further.
>
> Thanks.
>
> Mike
>
Sorry, I looked at your link and am still not sure this is correct if you are
already on the main thread.
[ThreadUtilities performOnMainThreadWaiting:YES block:^(){
+ (void)performOnMainThreadWaiting:(BOOL)wait block:(void (^)())block {
if ([NSThread isMainThread] && wait == YES) {
block();
} else {
if (wait == YES) {
[self performOnMainThread:@selector(invokeBlock:) on:self
withObject:block waitUntilDone:YES];
} else {
void (^blockCopy)(void) = Block_copy(block);
[self performOnMainThread:@selector(invokeBlockCopy:) on:self
withObject:blockCopy waitUntilDone:NO];
}
}
}
Given that the code is on the main thread and wait is indicated the code blocks
correct? Until when? If it is until it is off the main thread, does that
happen? Best case, whenever it comes out of the wait it falls through without
ever attempting to run the block at all doesn’t it? Wouldn’t correct be
something like…
+ (void)performOnMainThreadWaiting:(BOOL)wait block:(void (^)())block {
if ([NSThread isMainThread] && wait == YES) {
block();
}
if (wait == YES) {
[self performOnMainThread:@selector(invokeBlock:) on:self
withObject:block waitUntilDone:YES];
} else {
void (^blockCopy)(void) = Block_copy(block);
[self performOnMainThread:@selector(invokeBlockCopy:) on:self
withObject:blockCopy waitUntilDone:NO];
}
}
_______________________________________________
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