[M3devel] Win32 SuspendThread?
Jay K
jay.krell at cornell.edu
Mon Jan 20 00:13:24 CET 2014
"not worried" for native windows.
Still worried about wow64.
The answer for native is in Rotor/sscli and I have a program to show it working/not-working.
Specifically SuspendThread needs to be followed by GetThreadContext to ensure the suspend has completed.
If we don't do that, we must. If we already do, we are ok. I'll look later.
wow64 is still a problem. I'm still looking into it and thinking about it. But we do have native AMD64_NT
so just saying wow64 doesn't work might be the answer. I know people will protest that it works, but doesn't always.
I haven't figured out what rotor/sscli does.
Java uses cooperative suspend, which sidesteps this stuff.
- Jay
----------------------------------------
> To: jay.krell at cornell.edu
> CC: m3devel at elegosoft.com
> Subject: Re: [M3devel] Win32 SuspendThread?
> Date: Sun, 19 Jan 2014 12:05:48 -0800
> From: mika at async.caltech.edu
>
> "less worried" = "I think it works"?
>
> I think the only threading that works in CM3 is user threading...
>
> I tried to run CM3-compiled binaries through "valgrind" but got an
> error that CM3 is using the same signal that valgrind does internally
> (on AMD64_LINUX at least). I think this is easy to change in m3core
> (yes?) but haven't gotten around to it...
>
> valgrind has a threading checker called "helgrind"...
>
> Mika
>
> Jay writes:
>>
>>--Apple-Mail-79A8190D-B4F0-41F1-AA37-366ED17CF55A
>>Content-Type: text/plain;
>> charset=utf-8
>>Content-Transfer-Encoding: quoted-printable
>>
>>For native I'm less worried now. For wow64 I'm still worried & hope to follo=
>>w up further.
>>
>> - Jay
>>
>>On Jan 17, 2014, at 11:11 PM, "Coleburn, Randy" <rcolebur at SCIRES.COM> wrote:=
>>
>>
>>> Jay:
>>> =20
>>> I=E2=80=99m very concerned about the threading not working properly on bot=
>>h 32-bit and 64-bit Windows.
>>> =20
>>> The Thread Test program crashes for me on both platforms.
>>> =20
>>> I haven=E2=80=99t tried your new test program yet.
>>> =20
>>> --Randy
>>> =20
>>> From: jayk123 at hotmail.com [mailto:jayk123 at hotmail.com] On Behalf Of Jay K
>>> Sent: Saturday, January 18, 2014 1:23 AM
>>> To: m3devel
>>> Subject: EXT:[M3devel] Win32 SuspendThread?
>>> =20
>>> This program also doesn't behave as expected, native, nothing to do with w=
>>ow64.=20
>>> Anyone else please confirm:=20
>>> 1) my expectations -- it should never print anything
>>> 2) their importance -- garbage collector depends on it =20
>>> 3) their not being met -- stuff gets printed=20
>>> This is in the CVS repository, scratch/wow64stack/sync2.cpp=20
>>> I am following up further.=20
>>> Maybe we should get cooperative suspend really going?=20
>>> Thank you.
>>> - Jay=20
>>> =20
>>> #include <stdio.h>
>>> #include <windows.h>
>>> volatile long value;
>>> unsigned long __stdcall Thread(PVOID parameter)
>>> {
>>> while (1)
>>> InterlockedIncrement(&value);
>>> return 0;
>>> }
>>> int __cdecl main()
>>> {
>>> HANDLE thread =3D CreateThread(0, 0, Thread, 0, 0, 0);
>>> UINT i =3D 0;
>>> while (1)
>>> {
>>> i +=3D 1;
>>> if (SuspendThread(thread) =3D=3D (DWORD)-1)
>>> {
>>> printf("suspend failed %X\n", GetLastError());
>>> Sleep(1);
>>> continue;
>>> }
>>> volatile long a =3D value;=20
>>> volatile long b =3D value;
>>> if (a !=3D b)
>>> {
>>> printf("%d %d %d %d\n", i, a, b, b - a);
>>> }
>>> ResumeThread(thread);
>>> }
>>> }
>>
>>--Apple-Mail-79A8190D-B4F0-41F1-AA37-366ED17CF55A
>>Content-Type: text/html;
>> charset=utf-8
>>Content-Transfer-Encoding: quoted-printable
>>
>><html><head><meta http-equiv=3D"content-type" content=3D"text/html; charset=3D=
>>utf-8"></head><body dir=3D"auto"><div>For native I'm less worried now. For w=
>>ow64 I'm still worried & hope to follow up further.<br><br> - Jay</=
>>div><div><br>On Jan 17, 2014, at 11:11 PM, "Coleburn, Randy" <<a href=3D"=
>>mailto:rcolebur at SCIRES.COM">rcolebur at SCIRES.COM</a>> wrote:<br><br></div>=
>><blockquote type=3D"cite"><div>
>>
>><meta http-equiv=3D"Content-Type" content=3D"text/html; charset=3Dus-ascii">=
>>
>><meta name=3D"Generator" content=3D"Microsoft Word 14 (filtered medium)">
>><style>
>>
>>
>><div class=3D"WordSection1">
>><p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"Cal=
>>ibri","sans-serif";color:#1F497D">Jay:<o:p></o:p></span></p>
>><p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"Cal=
>>ibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p=
>>>
>><p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"Cal=
>>ibri","sans-serif";color:#1F497D">I=E2=80=99m very concerned a=
>>bout the threading not working properly on both 32-bit and 64-bit Windows.<o=
>>:p></o:p></span></p>
>><p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"Cal=
>>ibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p=
>>>
>><p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"Cal=
>>ibri","sans-serif";color:#1F497D">The Thread Test program cra=
>>shes for me on both platforms.<o:p></o:p></span></p>
>><p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"Cal=
>>ibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p=
>>>
>><p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"Cal=
>>ibri","sans-serif";color:#1F497D">I haven=E2=80=99t tried you=
>>r new test program yet.<o:p></o:p></span></p>
>><p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"Cal=
>>ibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p=
>>>
>><p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"Cal=
>>ibri","sans-serif";color:#1F497D">--Randy<o:p></o:p></span></=
>>p>
>><p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"Cal=
>>ibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p=
>>>
>><div>
>><div style=3D"border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0=
>>in 0in">
>><p class=3D"MsoNormal" style=3D"margin-left:.5in"><b><span style=3D"font-siz=
>>e:10.0pt;font-family:"Tahoma","sans-serif"">From:</span>=
>></b><span style=3D"font-size:10.0pt;font-family:"Tahoma","san=
>>s-serif""> <a href=3D"mailto:jayk123 at hotmail.com">jayk123 at hotmail.com</=
>>a> [<a href=3D"mailto:jayk123 at hotmail.com">mailto:jayk123 at hotmail.com</a>]
>><b>On Behalf Of </b>Jay K<br>
>><b>Sent:</b> Saturday, January 18, 2014 1:23 AM<br>
>><b>To:</b> m3devel<br>
>><b>Subject:</b> EXT:[M3devel] Win32 SuspendThread?<o:p></o:p></span></p>
>></div>
>></div>
>><p class=3D"MsoNormal" style=3D"margin-left:.5in"><o:p> </o:p></p>
>><div>
>><p class=3D"MsoNormal" style=3D"mso-margin-top-alt:0in;margin-right:0in;marg=
>>in-bottom:12.0pt;margin-left:.5in">
>><span style=3D"font-family:"Calibri","sans-serif""> =
>>;This program also doesn't behave as expected, native, nothing to do with wo=
>>w64.
>><br>
>> Anyone else please confirm: <br>
>> 1) my expectations -- it should never print anything<br>
>> 2) their importance -- garbage collector depends on it&nb=
>>sp; <br>
>> 3) their not being met -- stuff gets printed <br>
>> This is in the CVS repository, scratch/wow64stack/sync2.cpp <br>
>> I am following up further. <br>
>> Maybe we should get cooperative suspend really going? <br>
>>Thank you.<br>
>> - Jay <br>
>> <br>
>>#include <stdio.h><br>
>>#include <windows.h><br>
>>volatile long value;<br>
>>unsigned long __stdcall Thread(PVOID parameter)<br>
>>{<br>
>> while (1)<br>
>> InterlockedIncrement(&value);<br>
>> return 0;<br>
>>}<br>
>>int __cdecl main()<br>
>>{<br>
>> HANDLE thread =3D CreateThread(0, 0, Thread, 0, 0, 0);<br>
>> UINT i =3D 0;<br>
>> while (1)<br>
>> {<br>
>> i +=3D 1;<br>
>> if (SuspendThread(thread) =3D=3D (DWORD)-1)<br>
>> {<br>
>> printf("suspend failed %X\n", GetLastError())=
>>;<br>
>> Sleep(1);<br>
>> continue;<br>
>> }<br>
>> volatile long a =3D value; <br>
>> volatile long b =3D value;<br>
>> if (a !=3D b)<br>
>> {<br>
>> printf("%d %d %d %d\n", i, a, b, b - a);<br>
>> }<br>
>> ResumeThread(thread);<br>
>> }<br>
>>}<o:p></o:p></span></p>
>></div>
>></div>
>>
>>
>></div></blockquote></body></html>=
>>
>>--Apple-Mail-79A8190D-B4F0-41F1-AA37-366ED17CF55A--
More information about the M3devel
mailing list