[H-GEN] pthreads
Colin Ward
cward at auran.com
Thu Aug 26 01:05:50 EDT 1999
[ Humbug *General* list - semi-serious discussions about Humbug and
Unix-related topics. ]
Raymond Smith wrote:
>
> > 2. What if I really want to do this? because (just for instance :) ) I
> > might have a thread which modifies a structure, and then signals the
> > parent process that the structure has been modified, so that it in turn
> > can do things with it (including modify it).
> > What else could one do?
>
> You do not really want to do this. If you are using threads I would
> suggest have a global variable you set in the signal handler and another
> thread which periodically polls this variable and performs appropriate
> actions.
Pardon me, as I am a newcomer around here, but you should *never* use
variables for signalling that structures are safe to access. You simply
cannot be sure that the access to the variable is atomic, especially in
this day and age of programming in high level platform-neutral
languages. Who knows what code is generated to read or write a variable
on an X86, PPC or 68k CPU? The problems are worse if you use a
multi-CPU machine, where even a single assembly instruction is not
guaranteed to be atomic.
You use Mutexes and Semaphores for signalling as these will ensure
that the access is totally atomic for the CPU in use, usually by using
instructions specific to that CPU for atomic accesses, or disabling
interrupts.
Well this might be out of line becaue it's not Linux specific, and I
am a Linux newbie, but it is something which transcends the OS in use.
:-)
/---------------------------------------------------------------------\
[Hitman/Code HQ - 6502/68000/604e coder - Long live the Amiga! ]
[VZ-200/Vic-20/c16/c64*8/c128*8/Plus-4/CPC464/Amiga CD32/500/600/1000 ]
[2000/1200*2/3000UX/A4000/CV64-3D/060-50/604e-200/50 Meg. 6581 Rulez! ]
[After three days without coding, life becomes meaningless. ]
\---------------------------------------------------------------------/
--
This is list (humbug) general handled by majordomo at lists.humbug.org.au .
Postings only from subscribed addresses of lists general or general-post.
More information about the General
mailing list