Back to home page

DOS ain't dead

Forum index page

Log in | Register

Back to the forum
Board view  Mix view

HX: Sleep() + thread == hang? (DOSX)

posted by Johann "Myrkraverk" Oskarsson E-mail, 05.11.2007, 14:09

Hi all,

I tried to run the following application with HX, and for me, it hangs with the following output:

d:\dos\src>nt_thr.exe
Creating second thread...
second thread 0
third thread 0
third thread 1
   :
third thread 9


Is this a bug in HX? I believe I have the very latest version. I don't have NT so I can't test the app in "Real Windows", and I compiled it with the following command line:

wcl386 -l=hx -bt=nt -bm nt_thr.cpp

Here is ther source, adapted from an example I found on the web:

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

unsigned Counter;
void SecondThreadFunc( void* pArguments )
{
        for ( int i = 0; i < 10; i++ )
        {
                printf( "second thread %d\n", i );
                Sleep( 10 );
        }
}

void ThirdThreadFunc( void* pArguments )
{
        for ( int i = 0; i < 10; i++ )
        {
                printf( "third thread %d\n", i );
                //Sleep( 10 );
        }
}


int main()
{
HANDLE hThread2;
HANDLE hThread3;
unsigned threadID;

printf( "Creating second thread...\n" );

// Create the second thread.
hThread2 = (HANDLE)_beginthread(&SecondThreadFunc, 0, NULL);
hThread3 = (HANDLE)_beginthread(&ThirdThreadFunc, 0, NULL);


// Wait until second thread terminates. If you comment out the line
// below, the second thread will have no chance to finish
WaitForSingleObject( hThread2, INFINITE );
WaitForSingleObject( hThread3, INFINITE );


// Destroy the thread object.
CloseHandle( hThread2 );
CloseHandle( hThread3 );
}


EDIT by rr: added {code} tags for better readability

 

Complete thread:

Back to the forum
Board view  Mix view
22049 Postings in 2034 Threads, 396 registered users, 285 users online (0 registered, 285 guests)
DOS ain't dead | Admin contact
RSS Feed
powered by my little forum