Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Thread.spawn() crashes an Android #22963

Open
tsokano opened this issue Feb 21, 2025 · 5 comments
Open

Thread.spawn() crashes an Android #22963

tsokano opened this issue Feb 21, 2025 · 5 comments
Labels
bug Observed behavior contradicts documented or intended behavior os-android

Comments

@tsokano
Copy link

tsokano commented Feb 21, 2025

Zig Version

0.14.0-dev.3145+6a6e72fff

Steps to Reproduce and Observed Behavior

I am sorry that I have not been able to pinpoint the exact cause, but file this as an issue.

src.zip

This worked up to 42e48b8 but crashes after 6a6e72f.

export fn sokol_main() sokol.app.Desc {
    _ = std.Thread.spawn(.{}, hello, .{}) catch |e| {
        std.log.debug("{}", .{e});
    };
    ...

Adding this line causes a crash in main_anroid.zig.

Expected Behavior

No crash.

@tsokano tsokano added the bug Observed behavior contradicts documented or intended behavior label Feb 21, 2025
@alexrp
Copy link
Member

alexrp commented Feb 21, 2025

What kind of crash? Stack trace?

@tsokano
Copy link
Author

tsokano commented Feb 21, 2025

No stack trace. Terminate suddenly at this line.

@tsokano
Copy link
Author

tsokano commented Feb 21, 2025

However, I have confirmed that this works, so I know that Thread.spawn() itself is not the problem until.

const std = @import("std");

pub fn build(b: *std.Build) void {
	const target = b.standardTargetOptions(.{});
	const optimize = b.standardOptimizeOption(.{});
	const exe = b.addExecutable(.{
		.name = "android_test",
		.root_module = b.createModule(.{
			.root_source_file = b.path("main.zig"),
			.target = target,
			.optimize = optimize,
		}),
	});
	b.installArtifact(exe);
}
const std = @import("std");

pub fn main() !void {
	std.log.debug("Hello, Android!", .{});
	const thread = try std.Thread.spawn(.{}, hello, .{});
	thread.join();
}

fn hello() void {
	var i: u8 = 0;
	while (i<=3) : (i += 1) {
		std.log.debug("{}", .{i});
		std.Thread.sleep(1_000_000_000);
	}
}

zig build -Dtarget=aarch64-linux-android && adb push zig-out/bin/android_test /data/local /tmp && adb shell /data/local/tmp/android_test
This works as expected.
But, the application attached above also uses several C libraries, which makes it difficult for me to isolate and identify the cause.

@alexrp
Copy link
Member

alexrp commented Feb 21, 2025

No stack trace. Terminate suddenly at this line.

Well, try attaching a debugger?

@tsokano
Copy link
Author

tsokano commented Feb 21, 2025

I'm very sorry, but I don't understand usage of debugger on Andorid.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Observed behavior contradicts documented or intended behavior os-android
Projects
None yet
Development

No branches or pull requests

2 participants