Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2008-08

Off-topic: Threadvar in C

3 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Michael Schnell

Sorry to bother you by asking this here, but I don't know a better place. :(

I need to port a multi-threaded program in ANSI C. From a propriety OS to Linux.

Here the same code is started in multiple threads.

The OS provides a global variable that is preloaded with a "thread number" of the running thread (1, 2, 3, 4, .... n). This is something like a threadvar and can e.g. be used to create an array of records that holds thread specific values.

Now in Linux I need to use the pthread library. Here I don't find informations on how to hold thread specific values. Of course I could request the thread id and search a dedicated list of the created threads every time I need to access these values, but this would provide a _huge_ overhead. I can't believe that this is the way to go. And using a normal stack-variable is not practical at all as it would be necessary to pass it don the complete function hierarchy. A simple global integer preloaded with a predefinable number when the OS schedules a thread would be enough.

I suppose in Linux, FP uses the pthread library to create the TThread functionality. As the language provides the "threadvar" keyword, there needs to be a decent implementation of this functionality. I hope one of the compiler developers knows how this is done and/or where I can find this in the source code of the compiler and/or the rtl.

Thanks a lot !

-Michael

Reply by email

David W Noon
to Michael Schnell
Michael Schnell wrote
Sorry to bother you by asking this here, but I don't know a better place. :(

You could try Usenet: comp.os.linux.development.apps

Show quoted text 12 lines
I need to port a multi-threaded program in ANSI C. From a propriety OS to Linux. Here the same code is started in multiple threads. The OS provides a global variable that is preloaded with a "thread number" of the running thread (1, 2, 3, 4, .... n). This is something like a threadvar and can e.g. be used to create an array of records that holds thread specific values. Now in Linux I need to use the pthread library. Here I don't find informations on how to hold thread specific values.

man pthread_setspecific

man pthread_getspecific

could be good places to start.

Regards
Dave [RLU#314465]
====================================================== (David W Noon)
======================================================

Reply by email