strange behaviour with multithreading and C stdio

Open forum for end-user questions about Wine. Before asking questions, check out the Wiki as a first step.
Forum Rules
Locked
xetum
Newbie
Newbie
Posts: 1
Joined: Wed Feb 01, 2023 5:18 am

strange behaviour with multithreading and C stdio

Post by xetum »

I've the following code:

Code: Select all

#include <stdio.h>
#include <windows.h>
#include <process.h>

int main() {
    /* DWORD WINAPI */void input(/* LPVOID */void* lpParam) {
        Sleep(1000);
        printf("hello mingw!\n");
        // return 0;
    }
    _beginthread(input, 0, NULL);
    getchar();
    return 0;
}
I cross-compile from ubuntu 22.04.01 with mingw-w64 with:

...$ x86_64-w64-mingw32-gcc -o example.exe example.c

In a native Win7 box it works as expected:

...$ example.exe
hello mingw! (after 1 second)
a
...$

but in wine when entering 'a' from keyboard, the 'a' climbs up one line:

...$ example.exe
aello mingw!
...$

It seems as if printf output from a thread didn't update console cursor. This only happens when read code (getchar()) executes first than write code (printf),
hence the Sleep

Any pointers? Francesc
Locked