Using thread local variables instead of the global ones

Steve Lime Steve.Lime at DNR.STATE.MN.US
Thu Apr 27 23:40:43 EDT 2006

While I understand the issue and general solution you're beyond my expertise as a developer so I will defer to those with more experience.

In general, if there are changes such as this that make MapServer more appealing to languages like C# or Java without adversely affecting complexity then I support them. Especially if another developer is willing to do the implementation work.

Specifically regarding the lexer and parser though. As I understand it new versions of both Bison and Flex can output thread-safe code. Is it worth looking into that or are thread-local variables a more general solution so it's not worth worrying about?


>>> Szekeres Tamás <szekeres.tamas at FREEMAIL.HU> 04/27/06 6:31 PM >>>

According to the IRC conversation with Frank I would like to get to know the developer's affinity of this issue.

So it would be worth considering to make a support for using thread local variables instead of the global ones in the mapserver code.

1. It would add a significal increment on the performace of the applications having high number of multiple threads simultaneously.

2. This activity could bring in a more feasible support for some application models not really supported now like Microsoft ASP.NET

3. May result in higher clarity of the code by determining the variables affected by multiple threads.

The main drawback of this proposal is the need of to look over most of the existing code.

Frank has already worked on a solution targeting this problem for GDAL to utilize the Win32 TLS API and the Pthreads implementation.

In addition I would suggest to rely on the strorage specifiers existing for many of the platforms. It would be quite an easy to integrate into the existing code, like: 


#ifdef WIN32
#define MS_TLS __declspec( thread )
#ifdef __unix
#define MS_TLS __thread
#define MS_TLS

For declaring a thread local variable we could use:

static MS_TLS YY_BUFFER_STATE yy_current_buffer = 0;

Any of theese changes would imply some additional tests for the different platforms.

For additional information I would refer to

Any comment would be appreciated

Tamas Szekeres

No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.1.385 / Virus Database: 268.5.1/326 - Release Date: 2006.04.27.

More information about the mapserver-dev mailing list