Author: Robert Hyatt
Date: 14:08:03 07/25/99
Go up one level in this thread
On July 25, 1999 at 16:26:34, James Swafford wrote: >On July 25, 1999 at 13:45:36, Robert Hyatt wrote: > >>On July 24, 1999 at 17:19:31, James Swafford wrote: >> > >[snip] > >>5. create a global/shared variable initialized to 0. Whenever a thread notices >>it is 1, they exit. Then set this when needed... > > >ui_thread_is_dead is already a global variable. How >is this different than "shared," and how do I designate >it as shared? I can't answer for windows, but for unix, you have two ways to make things shared. 1. use the pthread library, which will make _all_ global variables shared. But then you use pthread_create() and not fork(). 2. use any of the shared memory facilities to create a block of shared memory and then use that via a pointer, rather than normal variable (shmget/shmat is one way, mmap() is another way). > >Under MSVC, *all* the global variables were shared, so >if one thread modified a global, the other thread would >see it. That doesn't appear to be the case here. if you have a fork()-like primitive under windows, it should not behave like this, otherwise it will break a large number of programs that depend on fork() making totally independent processes.... so that things like execve() and such will work as expected... > >The program is designed in such a way that all the global >variables are assumed to be shared between threads. If this >isn't the case when using fork( ), I could be in for some >long nights. :-/ Is there a way to designate *all* globals >as "shared?" (Or am I still missing something here?) > using fork, no... but you can create a shared memory region with mmap() or shmget/shmat, then fork, and both threads will still see that block of shared memory. put your shared stuff in there and both can see it. Of course, you had _better_ be using some sort of mutex/semaphore facility to protect things from interleaved updating... >Thanks. > >-- >James
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.