Program with System.Timers.Timer runned via mono project causes high CPU load - mono

I've noticed that programs where usage of System.Timers.Timer object appears is very CPU consumptive (almost 100percent for single CPU core).
I'm using Ubuntu 11.10, here is my version of mono:
mono -V
Mono JIT compiler version 2.10.5 (Debian 2.10.5-1)
Copyright (C) 2002-2011 Novell, Inc, Xamarin, Inc and Contributors. www.mono-project.com
TLS: __thread
SIGSEGV: altstack
Notifications: epoll
Architecture: amd64
Disabled: none
Misc: softdebug
LLVM: supported, not enabled.
GC: Included Boehm (with typed GC and Parallel Mark)
Here is sample program, which causes unexpected high CPU usage:
using System;
using System.Timers;
namespace MonoCPUTest
{
class Program
{
static Timer _refresh = new Timer();
static void Main(string[] args)
{
_refresh.Interval = 2000;
_refresh.AutoReset = true;
_refresh.Elapsed += (x, y) => refresh();
_refresh.Start();
while (true)
{
Console.WriteLine("loop");
System.Threading.Thread.Sleep(10000);
}
}
static void refresh()
{
Console.WriteLine("refresh");
}
}
}
Thank you very much for any help.

I've just tested (by copy pasting, compiling and executing your code) and cannot reproduce the issue, the CPU load is about 0. I'm using newer version of Mono, specifically the one compiled from the git tree couple days ago; so if there was an issue like that, it was fixed.
I guess upgrading your Mono is not possible without external PPA, but this is what should be done here if you are not forced to use this version for some other reason. You can also compile one from the source, which is as easy, as configure, make, make install ;)

Related

Compose plugin creates only Dmg distribution

I have desktop app written with compose, I am workinkg on Mac. Everything works fine for mac builds, but I am unable to produce one for linux.
dependencies {
implementation(compose.desktop.linux_x64)
implementation(compose.desktop.macos_x64)
[...]
}
compose.desktop {
application {
mainClass = "pl.rtsm.myapp.ApplicationKt"
jvmArgs += listOf("-Xmx12G")
nativeDistributions {
targetFormats(TargetFormat.Deb, TargetFormat.Dmg)
outputBaseDir.set(project.buildDir.resolve("installers"))
packageName = "MyApp"
}
}
}
Whatever I specify in targetFormats it only produces Mac app. Only thing in debug logs I've found is that this task is skipped (even though I am running task from clean state):
2022-01-09T18:11:57.948+0100 [LIFECYCLE] [class org.gradle.internal.buildevents.TaskExecutionLogger] > Task :packageDeb SKIPPED
2022-01-09T18:11:57.948+0100 [INFO] [org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter] Skipping task ':packageDeb' as task onlyIf is false.
Is it possible to create linux builds on Mac? Something is missing?

macOS App Crashes on 10.13 with Symbol not found: _NSAppearanceNameDarkAqua

I am building a macOS app with Deployment Target 10.13
Works on 10.15 but crashes on 10.13
Termination Reason: DYLD, [0x4] Symbol missing
Application Specific Information:
dyld: launch, loading dependent libraries
Dyld Error Message:
Symbol not found: _NSAppearanceNameDarkAqua
You'll need to make the code that uses this variable dependent on the version of macOS that's executing:
if (#available(macOS 10.14, *)) {
return NSAppearanceNameDarkAqua;
} else {
return nil;
}
You can also go old-school and declare it as a weak link:
extern NSAppearanceName const NSAppearanceNameDarkAqua __attribute__((weak_import));
...
if (NSAppearanceNameDarkAqua!=NULL) {
...
Makes sense; dark mode wasn't introduced until 10.14. So if you're going to run on 10.13, you mustn't load anything — not code, not asset catalog, not storyboard — that "mentions" or depends upon light/dark mode.

My RELEASE framework file is bigger than DEBUG framework

I have a kotlin multi-platform project for which I am creating a release framework. My release framework is bigger than the debug framework.
Following is the gradle task to create the framework:
task packForXcode(type: Sync) {
final File frameworkDir = new File(buildDir, "xcode-frameworks")
final String mode = 'RELEASE'
final def framework = kotlin.targets.iosArm64.binaries.getFramework(frameworkName, mode)
inputs.property "mode", mode
dependsOn framework.linkTask
from { framework.outputFile.parentFile }
into frameworkDir
doLast {
new File(frameworkDir, 'gradlew').with {
text = "#!/bin/bash\nexport 'JAVA_HOME=${System.getProperty("java.home")}'\ncd '${rootProject.rootDir}'\n./gradlew \$#\n"
setExecutable(true)
}
}
}
The framework file generated when mode = 'RELEASE' is 5.3 kb but when mode = 'DEBUG' one is 3.8 Kb.
I have 2 questions:
Is this expected ?
How can reduce or remove unused code while creating such a framework like R8/pro-guard in android ?
This result can be expected, as only release frameworks are embedding bitcode, debug ones have only bitcode markers(see some details here). Unused code should be already removed by the compiler, so there is no need to apply other tools here.

Android ndk different cflags

I have 3 projects in Android Studio: producer, consumer, and lib.
Lib is a shared JNI library in which I define a few functions to behave differently while others the same depending on how they're used. For example:
void function() {
#ifdef PRODUCER
printf("I'm a producer!\n");
#endif // PRODUCER
#ifdef CONSUMER
printf("I'm a consumer!\n");
#endif // CONSUMER
}
I'd like my gradle.build script for lib to basically have two potential flavors: producer & consumer then specify a dependency in the other projects like compile project(':lib:producer') or project(':lib:consumer'). These different targets would only vary in the following:
android {
defaultConfig {
ndk {
cFlag "-DPRODUCER" // or -DCONSUMER
}
}
}
Is this possible?
Turns out the best thing to do here was upgrade to Android Studio 2.2+ then use the externalNativeBuild's CMake to generate multiple libraries.

Mono Tesseract 3 ddlmap can't map liblept172.so

I want to use tesseract 3 nuget package with mono. I have a dll not found error at runtime : System.DllNotFoundException : Failed to find library liblept172.so for platform x64.
I tried to add a config file in the same folder of dll , and in et/mono/config too.
<dllmap dll="liblept172.dll" target="/usr/lib/liblept.so"/>
I tried rename dll in liblept.dll.
I added /usr/lib to ldconfig and i linked liblept172.so to liblept.so with no result. Is someone using tesseract 3 with mono (archlinux) ?
using System;
using Tesseract;
using System.Drawing;
namespace tesstessarct
{
class MainClass
{
public static void Main (string[] args)
{
using (TesseractEngine engine = new TesseractEngine (#"/usr/share/tessdata", "fra", EngineMode.TesseractOnly, "config"))
{
engine.SetVariable("tessedit_char_whitelist", "0123456789");
var page = engine.Process (new Bitmap("/test.jpg"));
Console.Write (page.GetText ());
}
}
}
}
The Tesseract Nuget :
<package id="Tesseract" version="3.0.2.0" targetFramework="net45" />
Is only the .Net/Mono wrapper. You will also need the language files and the native shared libraries built for ArchLinux
Build from Source: https://github.com/tesseract-ocr/tesseract
Install from package: https://www.archlinux.org/packages/community/i686/tesseract/