Subject: In search of further information about c-client and multi-threading...

From: Kenneth Maupin <[email-masked]>
Date: Thu, 20 Mar 1997 10:59:31 -0800

Hi,

	Is there documentation anywhere that describes in detail the issues
involved in using c-client with a multi-threaded application?  Pointers
to sample code would also be helpful.  I'm new to multi-threaded
application development and am looking for some elaboration on the
documentation in "Internal.DOC".

	Thanks!

				- Ken Maupin -
				[email-masked]

---

From: Chris Newman <[email-masked]>
Date: Thu, 20 Mar 1997 11:42:39 -0800 (PST)

> documentation in "Internal.DOC".

c-client is not designed for use with a multi-threaded application.  It
uses tons of non-thread safe library calls (strtok, readdir, ctime,
gethostbyname, etc) and has lots of global variables.  While a lot of it
passes context around in the form of a MAILSTREAM, the library often
passes around NIL MAILSTREAMs.  The effect is that almost every function
call has to be changed to pass context.

You're probably better off starting from scratch and just stealing the
good ideas from c-client (e.g. driver model, bezerk UID model, etc) if you
want a multi-threaded application.

---

From: Mark Crispin <[email-masked]>
Date: Thu, 20 Mar 1997 12:42:09 -0800 (PST)

On Thu, 20 Mar 1997 11:42:39 -0800 (PST), Chris Newman wrote:
> gethostbyname, etc) and has lots of global variables.

A slight correction:  Most of the global variables in c-client are those which
are appropriate for all threads, and probably should be shared across threads.

The non-thread safe library calls are a different matter.  Personally, I
consider that to be bad design in the C library.  While some, such as
strtok(), are obviously problematic (by the way, I think that all ctime()
calls are gone now), there's no excuse for gethostbyname() etc to be unsafe.

Nonetheless, it's a real concern.  I understand that there are even some stdio
implementations are also not thread-safe!

> want a multi-threaded application.

The other option is to substitute your own thread-safe C library.

---

From: Bill Yeager <[email-masked]>
Date: Thu, 20 Mar 1997 13:20:10 -0800 (PST)

>documentation in "Internal.DOC".

We've multithreaded the c-client (proprietary code), and it is a pain but
acheivable. You must really understand the structure of the code - and
seriously restructure it.

It was worth the effort!

Bill

---

From: Bill Yeager <[email-masked]>
Date: Thu, 20 Mar 1997 13:32:36 -0800 (PST)

>are appropriate for all threads, and probably should be shared across threads.
 Right. But, the REAL problem is creating a SAFE way of passing these
parameters to routines since they can no longer be GLOBAL. Different streams
need private copies of nearly all globals. The globals are for the most part
well organized, but as Chris said, the NIL stream is a killer you need to
eliminate, and then we have all of those mm_* calls that do not pass a stream,
and all of those other functions that use globals to which no stream is
passed. Tons of problems BUT one can do it.

>implementations are also not thread-safe!

Finally, the SIMPLE part was substituting already MT-Safe versions of the
various library calls. Only one was problematic, and it was not
gethostbyname()!

This is NOT to knock Mark's code. MT-Safe is not a major concern when you need
to port across multiple platforms which is difficult enough.

Bill

---

From: Kenneth Maupin <[email-masked]>
Date: Thu, 20 Mar 1997 16:19:57 -0800

> The other option is to substitute your own thread-safe C library.

	I should've mentioned in my original message that I'm developing
primarily in NT 4 and Win95 using Visual C++ 4.2.  Assuming libcmt.lib
and friends in the Visual C++ library are thread-safe, which parts of
c-client remain unsafe?

	Thanks for all of your repsonses on this topic...

					- Ken -