Re: windows threads work!!

new topic     » goto parent     » topic index » view thread      » older message » newer message

Hi Pete,
I modified my sample code adding the code you suggested but don't get any crash.
But the line puts(1,"lower(AAA)!=aaa\n") doesn't print anything.
Further reading form MSDN learned me that C run time library (CRT) must be a
multi-threaded version for a program using multi-thread with CRT functions to
work properly.
I think that those functions of euphoria that fails are those that call crt
functions and I guess
that exwc.exe version 2.5 is not linked with a multi-threaded version of CRT.

Concerning euphoria variables not being accesible by the thread function, its
wrong.  A thread function is a callback function like any windows functions and
it can access all euphoria object.
In my example spinlock and counter are euphoria global variables and
IncCounter() access them successfully.

In fact the only problem here is the fact that the euphoria interpreter is not
linked with a multi-threaded version of CRT.
By the way it work without any crash on my machine because all CRT dll that
comes with windows xp are multi-threaded versions.
But it fail with crt functions that are statically linked with exwc.exe

Maybe Robert Craig could confirm my hypothesis about static linkage of CRT in
exwc.exe

Regards,
Jacques DeschĂȘnes


Pete Lomax wrote:
> 
> On Mon, 10 Jul 2006 07:00:41 -0700, jacques desch=EAnes
> <guest at RapidEuphoria.com> wrote:
> 
> >In the past I tested threads in euphoria without any success. At my
> >first try and didn't insist because At that time i thought it was a
> >limitation of euphoria interpreter.
> It is. Btw, your example does not run on 2.4.
> >But this morning reading "windows internals" I learned that windows
> >create a new stack for each thread a process create. if so multithread
> >should in euphoria!
> >I decided to revisit it and IT WORKED!!
> If you use Eu to create pure windows/c_func threads then all will be
> fine. However Eu vars are not held on the windows stack, so using Eu
> code will fail; eg in function IncCounter after while 1 do add:
> }}}
<eucode>
>  if not equal(lower("AAA"),"aaa") then
>     puts(1,"lower(AAA)!=aaa\n")
>     if getc(0) then end if
>     abort(0)
>  end if
> </eucode>
{{{

> and after while spinlock < 2 do add:
> }}}
<eucode>
>  if not equal(lower("BBB"),"bbb") then
>     puts(1,"lower(BBB)!=bbb\n")
>     if getc(0) then end if
>     abort(0)
>  end if
> </eucode>
{{{

> Also, replace Sleep(500) with c_proc(iSleep,{500}) to avoid an almost
> inevitable type check on ms.
> The resulting program will fail or crash at random.
> 
> TDLL in the archives shows how you can multi-OS-thread C/asm code from
> Eu, but you cannot multi-OS-thread Eu code, not without doing
> something like converting it to a dll first.
> 
> Regards,
> Pete
> PS It is also not as simple as two threads calling the same routine
> (lower) simultaneously; the glitch in Sleep() shows it is re-using
> internal temporaries or something; if you comment out the lower call
> inside IncCounter, it works until the end, but the 'return 0' seems to
> spanner the last lower call from the main pgm.
> 
> PPS Al: the example did not work for me at all on Eu 2.4 but did on Eu
> 2.5 (on win98), until as above I replaced Sleep() with c_func and then
> 2.4 nearly got to the end before crashing blink)
> 
>

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu