[mercury-users] multi threading problem

Pieter Laeremans pieter at kotnet.org
Wed Dec 4 13:33:01 AEDT 2002


Hi,

I've got a multi threading problem.

>From the following code I would suspect that I would print some lines

:- module main.
:- interface.
:- import_module io.

:- pred main(io__state::di, io__state::uo) is cc_multi.
:- implementation.

:- import_module spawn.
:- import_module list.
:- import_module string.
:- pragma foreign_decl("C", "#include <stdio.h>").

:- pred testpred(int::in, io__state::di, io__state::uo) is cc_multi.
testpred(I) -->
	io__format("Inside test pred %i", [i(I)]),
        yield,
	sleep,
	testpred(I).



:- pred sleep(io__state::di, io__state::uo) is det.
:- pragma foreign_proc("C", sleep(IO0::di, IO::uo), [], "
     sleep(2);
     IO = IO0;
").

:- pragma promise_pure(sleep/2).



:- pred infinite(io__state::di, io__state::uo) is det.
infinite(!IO) :- io__write("something", !IO), yield(!IO), sleep(!IO), infinite(!IO).


main-->
	io__nl,
	io__write("Let 's perform a little test!"),
	spawn(testpred(1)),
	spawn(testpred(2)),
	infinite,
	io__nl.


	





Inside test pred 1
Inside test pred 2
Inside test pred 2
Inside test pred 1
....


But it does not. My terminal stays blank, and the program isn't
consuming any cpu. Does anyone has some explanation for this ?

Thanks in advance,

Pieter



--------------------------------------------------------------------------
mercury-users mailing list
post:  mercury-users at cs.mu.oz.au
administrative address: owner-mercury-users at cs.mu.oz.au
unsubscribe: Address: mercury-users-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-users-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the users mailing list