Subject: RE: BAD NEWS - Apache 1.2b10 on NT
From: [email-masked] (Colin Peters)

15 May 1997 23:36:53 -0700
Sender: [email-masked]
Approved: [email-masked]
Distribution: cygnus
Message-ID: <01BC6208.5EF05380.cygnus.gnu-win32@gbird0>
Original-To: "'Giovanni Maruzzelli'" <[email-masked]>
Original-Cc: "'GNU-Win32'" <[email-masked]>
MIME-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Original-Sender: [email-masked]

Giovanni Maruzzelli[SMTP:[email-masked]] wrote:
>2) if you connect from two machine at the same time it crash
>
>I think the problem is that all threads share the same memory, so, if they
>try to modify at the same time, they crash.
>I'vealso utilized a lot of Mutex, but this don't help.
>
>There's no mean to have memory storage space reserved for a thread.

It probably won't make your problems go away but there *are* ways of
reserving memory space on a per-thread basis using the Win32 API.
Unfortunately the use of these functions will probably require
massive changes to the overall form of the server threads... which
probably won't be worth it to you...

Anyway you can look in the book Advanced Windows by Jeffery Richter
(Microsoft Press), chapter 12 "Thread Local Storage" or look at the
Win32 API documents for TlsAlloc, TlsFree, TlsSetValue and
TlsGetValue. Basically the main program allocates a thread local
index using TlsAlloc. Then the multi thread code sets the value
associated with this index using TlsSetValue (for example to point
to a block of memory holding thread local data), probably right at
the start of the new thread. Whenever any function uses TlsGetValue
to obtain the value associated with the index (put it in a static
variable so that all threads can see it) it sees the value
associated with the current thread, and each thread gets its own
value.

If GCC supported the __declspec(thread) syntax (or some equivalent)
then you could simply mark all your thread local "static" or "global"
variables with that and everything would be simpler, but I don't
think that is likely to work now or anytime soon.

If the problem is caused by data that really is supposed to be
shared then I suggest you keep looking at your mutexes and critical
sections, because it should be possible to make things work that
way.

Note that the default process heap is serialized, so it should be
safe to call malloc or, failing that, HeapAlloc, from within threads.

Anyway, just wanted to clear that up (or is that make it even
muddier? :) ).

Colin.

-- Colin Peters - [email-masked]
-- Saga University Dept. of Information Science
-- http://www.fu.is.saga-u.ac.jp/~colin/index.html
-- http://www.geocities.com/Tokyo/Towers/6162/

-
For help on using this list (especially unsubscribing), send a message to
"[email-masked]" with one line of text: "help".