kamalp
8/10/2004 6:52:00 PM
rajesh.rajguru@wipro.com (Rajesh Rajguru) wrote in message news:<69d61a0b.0408062349.3b1730d7@posting.google.com>...
> We have a library which is used by many applications.This library has
> two cache files(always one will be active)
> Now we want to implement the threads in our library such a that every
> application (process) using this library ,will create its own thread
> and will keep running in its thread context. In this thread context we
> will try to map the active cache file
> We are thinking for following type of pseudo-code
>
> void *refresh(void *arg)
> {
> //static mutex declaration
> // pthread_try_lock()
> // if locking is successful , wait for some time and map the active
> cache file
> //else exit thread
> }
>
> main()
> {
> //create thread (refresh will be passed as parameter)
>
> }
>
> As many processes will try to create the their threads (as they access
> the same library), do you think of any problems in such types of
> implementation ?
I hope you are aware of the process-model on UNIX that encapsulates
thread instances. I mean, when a process creates a thread -it is
unique to that process, pretty much like malloc()ing inside a process.
When the code is in a library, each process linked with that library
has its own data segment on which the library malloc()'es, even though
the text segment is in the library (if it is a shared one -in case of
statically linked lib, the text segment is part of the
process/program). If you create a thread inside a library function,
that is as good as creating a thread inside one of the program's
functions -and it does not matter how many programs are linked to the
library or how many instances of such programs are in execution at the
same time.
> Will there be any problems if main process gets signal ?
>
You must mean main thread -which is the thread executing main().
When the signal is sent to the process, threads which have not set
their sigmask will receive the signal.
regards
-kamal
> Thanks & Regards,
> Rajesh