I've now tried to do a simple POSIX thread experiment, and I wonder if anyone can explain why it always causes gforth to crash. I've included the source and the crash below. If the comment in readThread is removed, output is produced but it crashes quickly. With the comment, it does not crash until you hit a key. I've tried various combinations, but haven't found anything that appears to work. Am I doing something wrong, or is gforth simply not pthread safe?

#! /usr/bin/env gforth

[IFUNDEF] library require lib.fs [THEN]

library libc /usr/lib/libc.dylib

4 (int) libc pthread_create pthread_create
1 (int) libc pthread_cancel pthread_cancel

variable readArmed  0 readArmed !
variable theReadThread

callback 1:0 (void) int callback;

:noname ( thing -- )
\       begin  readArmed @  while  5 .  repeat
; 1:0 readThread

: startRead ( -- )
        readArmed @ 0= if
                theReadThread 0 readThread 0 pthread_create .
                1 readArmed !
        then
;

: stopRead ( -- )
        theReadThread @ pthread_cancel .
        0 readArmed !
;

: t ( -- )                                      \ toggle read thread
        readArmed @ if
                stopRead
        else
                startRead
        then
;

Last login: Mon May  3 07:40:15 on ttyp2
/Users/DaR/Desktop/pThread.fs; exit
Welcome to Darwin!
Dennis-Ruffers-Computer:~ DaR$ /Users/DaR/Desktop/pThread.fs; exit
Gforth 0.6.2, Copyright (C) 1995-2003 Free Software Foundation, Inc.
Gforth comes with ABSOLUTELY NO WARRANTY; for details type `license'
Type `bye' to exit
t t 0 0  ok

*the terminal*:1: Address alignment exception
t t
  ^
Backtrace:
$208EC0 @
$804A2C
$208EEC >in
$20A0F8 parse-word
$212194 (recover)
$2083BC type
$212194 (recover)
$21CF58 (key)
$20CEBC key
$20CF1C edit-line
$20D260 accept
$20CF84 perform

DaR


--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to