[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [help-serveez] Thread safety

From: stefan
Subject: Re: [help-serveez] Thread safety
Date: Fri, 6 Dec 2002 13:07:37 +0100 (CET)

On 6 Dec 2002, Andreas Rottmann wrote:

> Hi!


First of all:  Serveez is not and will never be thread-safe. Period.

> I'm using threads in my serveez-based application and now wonder about
> the thread-safety of svz_log() (since it would be nice to be able to
> use it from the additional threads, too). AFAICT, There are the
> following issues:
> a) Thread safety of the C stdio functions (FILE *). I'm not really
>    sure about this, but I guess they are not really thread-safe when used
>    on the same FILE *.
> b) svz_log uses localtime, which is not thread-safe. However,
>    according to the libc info, there is localtime_r, defined by
>    POSIX.1c.
> c) svz_log accesses svz_config (see a)) and svz_logfile, so they would
>    need to be locked.

However it should be possible to make some API functions of Serveez
thread-safe.  'svz_log' looks like a reasonable candidate.  The easiest
way to implement this would be to define a static (access lock) variable
inside svz_log.  The problem is: Serveez does not use any thread API.
Therefore we need a sleep()'y loop (waiting for the (access) variable) or
something.  Any better idea?

> Solutions would be IMO:
> a) Simply lock access to svz_logfile. This can be done quite easily,
>    because svz_logfile is static.
> b) Use localtime_r, if available.
> c) This is a bit hairy. svz_config is *not* static. IMO, It would be
>    wise to make it static and use accessor functions. Then it could be
>    locked.
> I'd be glad to provide a patch that makes svz_log thread-safe (or
> mostly so ;-)), but before I want to hear comments on c), since making
> svz_config static would result in API breakage.

Actually I forgot why svz_config is not static...

Bottom line: How do we implement a synchronization mechanism?


reply via email to

[Prev in Thread] Current Thread [Next in Thread]