diff --git a/src/modules/Image/image.c b/src/modules/Image/image.c
index 84cef371d3a81c8a88f243eadd3a9b4642927166..cc11cd0c6bdfbef589b15f97be04aaa75c1089b5 100644
--- a/src/modules/Image/image.c
+++ b/src/modules/Image/image.c
@@ -1,4 +1,4 @@
-/* $Id: image.c,v 1.43 1997/10/21 13:32:13 mirar Exp $ */
+/* $Id: image.c,v 1.44 1997/10/21 18:39:36 grubba Exp $ */
 
 /*
 **! module Image
@@ -6,7 +6,7 @@
 **!     This module adds image-drawing and -manipulating
 **!	capabilities to pike. 
 **! note
-**!	$Id: image.c,v 1.43 1997/10/21 13:32:13 mirar Exp $<br>
+**!	$Id: image.c,v 1.44 1997/10/21 18:39:36 grubba Exp $<br>
 **! see also: Image.font, Image.image
 **!
 **! class image
@@ -107,7 +107,7 @@
 
 #include "stralloc.h"
 #include "global.h"
-RCSID("$Id: image.c,v 1.43 1997/10/21 13:32:13 mirar Exp $");
+RCSID("$Id: image.c,v 1.44 1997/10/21 18:39:36 grubba Exp $");
 #include "pike_macros.h"
 #include "object.h"
 #include "constants.h"
@@ -303,6 +303,7 @@ static INLINE rgb_group _pixel_apply_matrix(struct image *img,
   /* NOTE:
    *	This code MUST be MT-SAFE!
    */
+  HIDE_GLOBAL_VARIABLES();
    rgb_group res;
    int i,j,bx,by,xp,yp;
    int sumr,sumg,sumb,r,g,b;
@@ -342,6 +343,7 @@ static INLINE rgb_group _pixel_apply_matrix(struct image *img,
    fprintf(stderr,"->%d,%d,%d\n",res.r,res.g,res.b);
 #endif
    return res;
+   REVEAL_GLOBAL_VARIABLES();
 }
 
 
@@ -1128,10 +1130,12 @@ static INLINE void
   /* NOTE:
    *	This code MUST be MT-SAFE!
    */
+  HIDE_GLOBAL_VARIABLES();
    sum->r=testrange(sum->r+(INT32)(rgba.r*factor+0.5));
    sum->g=testrange(sum->g+(INT32)(rgba.g*factor+0.5));
    sum->b=testrange(sum->b+(INT32)(rgba.b*factor+0.5));
    sum->alpha=testrange(sum->alpha+(INT32)(rgba.alpha*factor+0.5));
+   REVEAL_GLOBAL_VARIABLES();
 }
 
 static INLINE void
@@ -1142,9 +1146,11 @@ static INLINE void
   /* NOTE:
    *	This code MUST be MT-SAFE!
    */
+  HIDE_GLOBAL_VARIABLES();
    sum->r=testrange(sum->r+(INT32)(rgba.r*factor+0.5));
    sum->g=testrange(sum->g+(INT32)(rgba.g*factor+0.5));
    sum->b=testrange(sum->b+(INT32)(rgba.b*factor+0.5));
+   REVEAL_GLOBAL_VARIABLES();
 }
 
 /*
diff --git a/src/modules/Image/lzw.c b/src/modules/Image/lzw.c
index 853c0ce35790cda257de52e740fe911f80cc7a06..a68c969fe97cc72063b918b50d335587ed9f070c 100644
--- a/src/modules/Image/lzw.c
+++ b/src/modules/Image/lzw.c
@@ -1,4 +1,4 @@
-/* $Id: lzw.c,v 1.2 1997/05/29 19:37:43 mirar Exp $ */
+/* $Id: lzw.c,v 1.3 1997/10/21 18:39:37 grubba Exp $ */
 
 /*
 
@@ -15,11 +15,13 @@ the existanse of #define GIF_LZW is for that purpose. :-)
 /*
 **! module Image
 **! note
-**!	$Id: lzw.c,v 1.2 1997/05/29 19:37:43 mirar Exp $<br>
+**!	$Id: lzw.c,v 1.3 1997/10/21 18:39:37 grubba Exp $<br>
 */
 
 #include "global.h"
 
+#include "threads.h"
+
 #include "lzw.h"
 
 #define DEFAULT_OUTBYTES 16384
@@ -32,6 +34,7 @@ static INLINE void lzw_output(struct lzw *lzw,lzwcode_t codeno)
    int bits,bitp;
    unsigned char c;
 
+   HIDE_GLOBAL_VARIABLES();
 /*
    fprintf(stderr,"%03x bits=%d codes %d %c\n",
            codeno,lzw->codebits,lzw->codes+1,
@@ -73,12 +76,14 @@ static INLINE void lzw_output(struct lzw *lzw,lzwcode_t codeno)
    }
    lzw->lastout=0;
    lzw->outbit=0;
+   REVEAL_GLOBAL_VARIABLES();
 }
 
 
 void lzw_init(struct lzw *lzw,int bits)
 {
    unsigned long i;
+   HIDE_GLOBAL_VARIABLES();
 #ifdef GIF_LZW
    lzw->codes=(1L<<bits)+2;
 #else
@@ -109,6 +114,7 @@ void lzw_init(struct lzw *lzw,int bits)
 #ifdef GIF_LZW
    lzw_output(lzw,1L<<bits);
 #endif
+   REVEAL_GLOBAL_VARIABLES();
 }
 
 void lzw_quit(struct lzw *lzw)
@@ -147,6 +153,7 @@ static void lzw_recurse_find_code(struct lzw *lzw,lzwcode_t codeno)
 
 void lzw_write_last(struct lzw *lzw)
 {
+  HIDE_GLOBAL_VARIABLES();
    if (lzw->current)
       lzw_output(lzw,lzw->current);
 #ifdef GIF_LZW
@@ -154,10 +161,12 @@ void lzw_write_last(struct lzw *lzw)
 #endif
    if (lzw->outbit)
       lzw->out[lzw->outpos++]=lzw->lastout;
+   REVEAL_GLOBAL_VARIABLES();
 }
 
 void lzw_add(struct lzw *lzw,int c)
 {
+  HIDE_GLOBAL_VARIABLES();
    lzwcode_t lno,lno2;
    struct lzwc *l;
 
@@ -218,6 +227,7 @@ void lzw_add(struct lzw *lzw,int c)
    if (lzw->codes>(unsigned long)(1L<<lzw->codebits)) lzw->codebits++;
 
    lzw->current=c;
+   REVEAL_GLOBAL_VARIABLES();
 }
 
 #undef UNPACK_DEBUG
diff --git a/src/modules/Image/togif.c b/src/modules/Image/togif.c
index f32b62eb3f0ea77255213c8d2b8af976e0cfb117..25a130e18175242c60ef34ae25fb3ed81253cfb2 100644
--- a/src/modules/Image/togif.c
+++ b/src/modules/Image/togif.c
@@ -4,14 +4,14 @@ togif
 
 Pontus Hagland, law@infovav.se
 
-$Id: togif.c,v 1.18 1997/10/12 21:11:12 mirar Exp $ 
+$Id: togif.c,v 1.19 1997/10/21 18:39:38 grubba Exp $ 
 
 */
 
 /*
 **! module Image
 **! note
-**!	$Id: togif.c,v 1.18 1997/10/12 21:11:12 mirar Exp $<br>
+**!	$Id: togif.c,v 1.19 1997/10/21 18:39:38 grubba Exp $<br>
 **! class image
 */
 
@@ -163,6 +163,7 @@ void image_floyd_steinberg(rgb_group *rgb,int xsize,
 			   struct colortable *ct,
 			   int closest)
 {
+  HIDE_GLOBAL_VARIABLES();
    rgbl_group err;
    int x;
 
@@ -188,6 +189,7 @@ void image_floyd_steinberg(rgb_group *rgb,int xsize,
 				    (x==0)?NULL:errl+x-1,
 				    &err,rgb[x],ct,closest);
    }
+   REVEAL_GLOBAL_VARIABLES();
 }
 		     
 #define STD_ARENA_SIZE 16384
@@ -619,41 +621,48 @@ CHRONO("begin pack");
 
    THREADS_ALLOW();
    lzw_init(&lzw,bpp);
+   THREADS_DISALLOW();
+
    if (!fs)
    {
-      if (closest)
-	 while (i--) lzw_add(&lzw,colortable_rgb_nearest(ct,*(rgb++)));
-      else
-	 while (i--) lzw_add(&lzw,colortable_rgb(ct,*(rgb++)));
-   }
-   else
-   {
+     THREADS_ALLOW();
+     if (closest)
+       while (i--) lzw_add(&lzw,colortable_rgb_nearest(ct,*(rgb++)));
+     else
+       while (i--) lzw_add(&lzw,colortable_rgb(ct,*(rgb++)));
+     THREADS_DISALLOW();
+   } else {
       rgbl_group *errb;
       int w,*cres,j;
+      /* NOTE: xalloc() is NOT thread-safe. */
       errb=(rgbl_group*)xalloc(sizeof(rgbl_group)*xs);
       cres=(int*)xalloc(sizeof(int)*xs);
+      THREADS_ALLOW();
       for (i=0; i<xs; i++)
 	errb[i].r=(rand()%(FS_SCALE*2+1))-FS_SCALE,
-	errb[i].g=(rand()%(FS_SCALE*2+1))-FS_SCALE,
-	errb[i].b=(rand()%(FS_SCALE*2+1))-FS_SCALE;
+	  errb[i].g=(rand()%(FS_SCALE*2+1))-FS_SCALE,
+	  errb[i].b=(rand()%(FS_SCALE*2+1))-FS_SCALE;
 
       w=0;
-      while (ys--)
-      {
-	 image_floyd_steinberg(rgb,xs,errb,w=!w,cres,ct,closest);
-	 for (j=0; j<xs; j++)
-	    lzw_add(&lzw,cres[j]);
-	 rgb+=xs;
+      while (ys--) {
+	image_floyd_steinberg(rgb,xs,errb,w=!w,cres,ct,closest);
+	for (j=0; j<xs; j++)
+	  lzw_add(&lzw,cres[j]);
+	rgb+=xs;
       }
-
-      free(errb);
+      THREADS_DISALLOW();
       free(cres);
+      free(errb);
    }
 
+   THREADS_ALLOW();
    lzw_write_last(&lzw);
+   THREADS_DISALLOW();
 
 CHRONO("end pack");
 
+   /* NOTE that the low_my_* functions are NOT thread-safe.
+    */
    for (i=0; i<(int)lzw.outpos; i+=254)
    {
       int wr;
@@ -666,8 +675,6 @@ CHRONO("end pack");
 
    lzw_quit(&lzw);
 
-   THREADS_DISALLOW();
-
 CHRONO("done");
 
    pop_n_elems(args);
diff --git a/src/modules/files/file.c b/src/modules/files/file.c
index 549a441477d575f88ed9b28b6d597cb093b0d432..6ea41273f069649b8d21ad6c4dce7090b6bfbf7d 100644
--- a/src/modules/files/file.c
+++ b/src/modules/files/file.c
@@ -6,7 +6,7 @@
 #define READ_BUFFER 8192
 
 #include "global.h"
-RCSID("$Id: file.c,v 1.58 1997/10/17 02:32:33 hubbe Exp $");
+RCSID("$Id: file.c,v 1.59 1997/10/21 18:39:34 grubba Exp $");
 #include "interpret.h"
 #include "svalue.h"
 #include "stralloc.h"
@@ -328,10 +328,13 @@ static struct pike_string *do_read(int fd,
     initialize_buf(&b);
     SET_ONERROR(ebuf, free_dynamic_buffer, &b);
     do{
+      char *buf;
       try_read=MINIMUM(CHUNK,r);
       
+      buf = low_make_buf_space(try_read, &b);
+
       THREADS_ALLOW();
-      i=read(fd, low_make_buf_space(try_read, &b), try_read);
+      i=read(fd, buf, try_read);
       THREADS_DISALLOW();
 
       check_signals(0,0,0);