[M3devel] threading on Windows?

Mika Nystrom mika at async.caltech.edu
Sun Feb 13 01:33:57 CET 2011


Jay K writes:
>--_879a340b-b2bb-415e-936c-be8d5cdd855c_
>Content-Type: text/plain; charset="iso-8859-1"
>Content-Transfer-Encoding: quoted-printable
>
>
>I assume he means "the thread tester should work"?
>But agreed=2C the vast vast vast vast majority of things are ok and have be=
>en ok for the vast vast vast majority of Modula-3's existance.
>  Even in recent years. pthreads and user threads.
>  Infinite loops with TRY in January 2011 would use infinite stack. Underst=
>ood.
>  Finite loops would merely use more than they should and reclaim upon func=
>tion return.
>cvsupd didn't work for a while with pthreads. Because of its use of "fork a=
>nd do more work" and its assumption
>that all threads survive fork. Relatively few programs do that and they wer=
>e all broken by pthreads.
>=20
>The new thread tester probably needs more attention.
>=20
> - Jay

My thread tester wasn't developed "ex nihilo".  It's based on analyzing
the failure modes of a larger application that I am prevented from
distributing the source code for, both for reasons of confidentiality
and practicality.

I have purposely written the tester to be "obviously correct" and I would
like nothing more than for someone to show me where I have made a mistake
and that pthreads are working as they should.

For example, here is the "alloc" thread:

PROCEDURE AApply(cl : Closure) : REFANY =
  BEGIN
    Thread.Pause(InitPause);
    LOOP
      VAR
        arr := NEW(REF ARRAY OF INTEGER, 1025);
      BEGIN
        FOR i := FIRST(arr^)+1 TO LAST(arr^) DO
          arr[i] := arr[i] - arr[i-1]
        END; times1[cl.id] := FLOOR(Time.Now())
      END
    END
  END AApply;

Is there anything here that is wrong or bad?  When I tried pthreads just now
on AMD64_LINUX, running two instances of AApply at the same time caused
the runtime to deadlock.  

[BTW, I have never seen a problem with user threads except for building
issues and the TRY-EXCEPT thing you just fixed.]

Unfortunately, since just about every Modula-3 program allocates memory,
my analysis is that because it appears you can deadlock the runtime by 
allocating memory, nothing is *really* OK with pthreads.  Please tell
me I'm wrong!

    Mika

P.S. backtraces of deadlock:

Thread 3 (Thread 0x40862950 (LWP 19974)):
#0  0x00002b9d49f730e1 in nanosleep () from /lib/libpthread.so.0
#1  0x000000000045806d in ThreadPThread__Nanosleep (req=Cannot access memory at address 0x140861b08
) at ../src/thread/PTHREAD/ThreadPThreadC.c:500
#2  0x0000000000454294 in ThreadPThread__CommonSleep () at ../src/thread/PTHREAD/ThreadPThread.m3:551
#3  0x0000000000456438 in ThreadPThread__StopWorld () at ../src/thread/PTHREAD/ThreadPThread.m3:1086
#4  0x0000000000455787 in RTThread__SuspendOthers () at ../src/thread/PTHREAD/ThreadPThread.m3:812
#5  0x000000000043970c in RTCollector__CollectSomeInStateZero () at ../src/runtime/common/RTCollector.m3:746
#6  0x00000000004396b8 in RTCollector__CollectSome () at ../src/runtime/common/RTCollector.m3:720
#7  0x00000000004390b9 in RTHeapRep__CollectEnough () at ../src/runtime/common/RTCollector.m3:654
#8  0x0000000000436111 in RTAllocator__AllocTraced (M3_Cwb5VA_dataSize=Cannot access memory at address 0x140861dc8
) at ../src/runtime/common/RTAllocator.m3:363
#9  0x000000000043596f in RTAllocator__GetOpenArray (M3_Eic7CK_def=Cannot access memory at address 0x140861eb8
) at ../src/runtime/common/RTAllocator.m3:292
#10 0x0000000000434ab1 in RTHooks__AllocateOpenArray (M3_AJWxb1_defn=Cannot access memory at address 0x140861f38
) at ../src/runtime/common/RTAllocator.m3:141
#11 0x0000000000407030 in Main__AApply (M3_AP7a1g_cl=Cannot access memory at address 0x140861f88
) at ../src/Main.m3:234
#12 0x0000000000453b3f in ThreadPThread__RunThread (M3_DMxDjQ_me=Cannot access memory at address 0x140862028
) at ../src/thread/PTHREAD/ThreadPThread.m3:475
#13 0x00000000004537d3 in ThreadPThread__ThreadBase (M3_AJWxb1_param=Cannot access memory at address 0x1408620d8
) at ../src/thread/PTHREAD/ThreadPThread.m3:447
#14 0x00002b9d49f6bfc7 in start_thread () from /lib/libpthread.so.0
#15 0x00002b9d4b3bd64d in clone () from /lib/libc.so.6
#16 0x0000000000000000 in ?? ()

Thread 2 (Thread 0x40661950 (LWP 19973)):
#0  0x00002b9d49f72384 in __lll_lock_wait () from /lib/libpthread.so.0
#1  0x00002b9d49f6dbf0 in _L_lock_102 () from /lib/libpthread.so.0
#2  0x00002b9d49f6d4fe in pthread_mutex_lock () from /lib/libpthread.so.0
#3  0x000000000045815e in ThreadPThread__pthread_mutex_lock (m=Cannot access memory at address 0x140660d68
) at ../src/thread/PTHREAD/ThreadPThreadC.c:557
#4  0x00000000004575af in RTOS__LockHeap () at ../src/thread/PTHREAD/ThreadPThread.m3:1434
#5  0x0000000000436107 in RTAllocator__AllocTraced (M3_Cwb5VA_dataSize=Cannot access memory at address 0x140660dc8
) at ../src/runtime/common/RTAllocator.m3:361
#6  0x000000000043596f in RTAllocator__GetOpenArray (M3_Eic7CK_def=Cannot access memory at address 0x140660eb8
) at ../src/runtime/common/RTAllocator.m3:292
#7  0x0000000000434ab1 in RTHooks__AllocateOpenArray (M3_AJWxb1_defn=Cannot access memory at address 0x140660f38
) at ../src/runtime/common/RTAllocator.m3:141
#8  0x0000000000407030 in Main__AApply (M3_AP7a1g_cl=Cannot access memory at address 0x140660f88
) at ../src/Main.m3:234
#9  0x0000000000453b3f in ThreadPThread__RunThread (M3_DMxDjQ_me=Cannot access memory at address 0x140661028
) at ../src/thread/PTHREAD/ThreadPThread.m3:475
#10 0x00000000004537d3 in ThreadPThread__ThreadBase (M3_AJWxb1_param=Cannot access memory at address 0x1406610d8
) at ../src/thread/PTHREAD/ThreadPThread.m3:447
#11 0x00002b9d49f6bfc7 in start_thread () from /lib/libpthread.so.0
#12 0x00002b9d4b3bd64d in clone () from /lib/libc.so.6
#13 0x0000000000000000 in ?? ()

Thread 1 (Thread 0x2b9d4d32a1a0 (LWP 19965)):
#0  0x00002b9d4b3202a2 in sigsuspend () from /lib/libc.so.6
#1  0x0000000000457ba9 in ThreadPThread__sigsuspend () at ../src/thread/PTHREAD/ThreadPThreadC.c:141
#2  0x0000000000456a0d in ThreadPThread__SignalHandler (M3_DLS2Hj_sig=Cannot access memory at address 0x80001dde057c
) at ../src/thread/PTHREAD/ThreadPThread.m3:1205
#3  <signal handler called>
#4  0x00002b9d49f6ffad in pthread_cond_timedwait@@GLIBC_2.3.2 () from /lib/libpthread.so.0
#5  0x00000000004580b3 in ThreadPThread__pthread_cond_timedwait (cond=Cannot access memory at address 0x80001dde0a88
) at ../src/thread/PTHREAD/ThreadPThreadC.c:515
#6  0x00000000004544cf in ThreadPThread__XPause (M3_DMxDjQ_self=Cannot access memory at address 0x80001dde0ab8
) at ../src/thread/PTHREAD/ThreadPThread.m3:580
#7  0x00000000004545b2 in Thread__Pause (M3_CtKayy_n=Cannot access memory at address 0x80001dde0b08
) at ../src/thread/PTHREAD/ThreadPThread.m3:595
#8  0x00000000004097ee in Main_M3 (M3_AcxOUs_mode=Cannot access memory at address 0x80001dde0bc8
) at ../src/Main.m3:449
#9  0x0000000000445799 in RTLinker__RunMainBody (M3_DjPxE3_m=Cannot access memory at address 0x80001dde0f58
) at ../src/runtime/common/RTLinker.m3:406
#10 0x00000000004448f2 in RTLinker__AddUnitI (M3_DjPxE3_m=Cannot access memory at address 0x80001dde0ff8
) at ../src/runtime/common/RTLinker.m3:113
#11 0x0000000000444990 in RTLinker__AddUnit (M3_DjPxE5_b=Cannot access memory at address 0x80001dde1018
) at ../src/runtime/common/RTLinker.m3:122
#12 0x000000000040652c in main (argc=Cannot access memory at address 0x80001dde1068
) at _m3main.mc:4




More information about the M3devel mailing list