Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: gcc / cygwin threads revisited

Author: Tim Mann

Date: 16:45:05 07/27/99

Go up one level in this thread


On July 24, 1999 at 17:19:31, James Swafford wrote:

>I posted a question several days ago about the gcc
>equivalent to MSVC's "beginthread( )" .
>
>Bob replied with "fork( )"

It looks like Bob caused a lot of confusion with this reply.

Win32's beginthread() creates a true thread running in the same address space as
the parent.  It has its own stack pointer and registers, but it shares all
memory (and hence all global variables) with its parent.

Unix's (and Cygwin's) fork() is a completely different concept.  It starts a
whole new process with a completely separate address space, but the new process
is initially an exact copy of the old one.  It's a bit like cloning yourself in
the science-fiction sense: suddenly there are two of you with the same memories,
but you're separate people from then on.

The Unix-ish equivalent to beginthread() is pthread_create().  I don't know
whether this routine is available in Cygwin, but it is available on Linux and
most other modern Unix flavors.  This is the primitive to use if you are porting
a program that uses beginthread().

Digression: In some operating systems, you can get an effect that is sort of
halfway between creating a thread and forking; you can create a new process that
shares *some* of its memory with the parent. This is more complicated than using
true threads because you have to tell the system what memory to share and what
not to. I guess it might make for easier parallelization of programs that were
written to be single-threaded and use a lot of global variables that need to
become per-thread variables, but I wouldn't recommend it for parallel programs
being written from scratch. Both Windows and Unix (most versions) have this kind
of functionality, but it can be a bit complicated to set up, and the way to do
it on Unix varies with different Unix versions.  Bob talked about doing this in
some of his later replies in this message thread.  Both Windows and Unix (most
versions) have this kind of functionality.  I don't suggest going this route,
especially if you want to port to Unix.  (Also, I have no idea whether it's
available in Cygwin, if you care about that.)  Vincent Diepeveen's parallel Diep
works this way, and it works well on Windows NT, but he's had a lot of pain
trying to port it to Linux because the shared memory implementation in Linux is
hard to use and has a rather low limit on the amount of memory that can be
shared.

	--Tim



This page took 0 seconds to execute

Last modified: Thu, 15 Apr 21 08:11:13 -0700

Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.