MT-safe sleeping ???

MT-safe sleeping ???

Post by Dan Du » Tue, 26 Sep 1995 04:00:00




>Hi,
> Is TIMER a per process resource ?  How can I do a thread level
> alarm ?  The problem I have is the following. In my program, I'm
> using > 2 threads. Each of them needs to use a timer for a
> specific task. When I set a timer in one thread using alarm(),
> some other thread also sets the alarm() and overrides this. How
> do I use thread level timer apart from using mutexs before alarm() ?

Instead of using timers, use cond_timedwait().  cond_timedwait() is
MT-Safe and has a much finer resolution than alarm().

see man condition for further explanation of the condition variable.

--
=========================================
Dan Dunn

=========================================

 
 
 

MT-safe sleeping ???

Post by Ramesh Nagabushn » Tue, 26 Sep 1995 04:00:00


Hi,
 Is TIMER a per process resource ?  How can I do a thread level
 alarm ?  The problem I have is the following. In my program, I'm
 using > 2 threads. Each of them needs to use a timer for a
 specific task. When I set a timer in one thread using alarm(),
 some other thread also sets the alarm() and overrides this. How
 do I use thread level timer apart from using mutexs before alarm() ?

I cannot afford to merge the threads into 1 process.

Is there a standard way to solve this problem ?

Thanks for any suggestions,

-ramesh

--
____________________________________________________
  Ramesh Nagabushnam,           (o) (914) 644-2711


 
 
 

MT-safe sleeping ???

Post by Ramesh Nagabushn » Wed, 27 Sep 1995 04:00:00



: > using > 2 threads. Each of them needs to use a timer for a
: > specific task. When I set a timer in one thread using alarm(),
: > some other thread also sets the alarm() and overrides this. How
: > do I use thread level timer apart from using mutexs before alarm() ?

: Instead of using timers, use cond_timedwait().  cond_timedwait() is
: MT-Safe and has a much finer resolution than alarm().

:  
: see man condition for further explanation of the condition variable.

: --
: =========================================
: Dan Dunn

: =========================================

Dan,
 thanks for the suggestion. However, I had mis-stated the problem in
 the subject.

 What I really need is some means of detecting a timeout in the same
 thread. For example, I have a thread that is attempting a TCP
 connect() to a remote machine. If the remote machine is down, then
 connect would take nearly 3 minutes to timeout. To overcome this I
 was trying something like this:

 try {
   TIMER connect_timer(duration);

   connect(...);
 }
 catch(..) {
   /* couldn't connect in 'duration' seconds ==> host/network is down */
   ..
 }

 The TIMER object sets the alarm(duration) and a SIGALRM handler that
 throws an exception on SIGALRM.

 This works ok on a single threaded environment but obviously not
 in a multi-threaded program  because different threads may be
 connecting to different machines.

 Is there an alternate way of doing this without using multiple proceses ?

thanks for any pointers,

-ramesh

____________________________________________________
  Ramesh Nagabushnam,           (o) (914) 644-2711

 
 
 

1. Difference Between 'Safe' And 'MT-Safe' ML-Level

MT-Level: Libraries are classified into four categories which define their
ability to support multiple threads. Manual pages containing routines that
are of multiple or differing levels show this within their NOTES or USAGE
section.
( See attributes(5) )

I do not understand the difference between Safe and MT-Safe.

Safe: ...Often overlooked is the fact that the result of this Safe interface
or safe code segment can have global consequences that affect all threads.

MT-Safe: Note that a library can be safe to use, but not MT-Safe. For
example, surrounding an entire library with a monitor makes the library
Safe, but it supports no concurrency so it is not considered MT-Safe. An
MT-Safe library must permit a reasonable amount of concurrency. (This
definition's purpose is to give precision to what is meant when a library is
described as Safe. The definition of a Safe library does not specify if the
library supports concurrency. The MT-Safe definition makes it clear that the
library is Safe, and supports some concurrency. This clarifies the Safe
definition, which can mean anything from being single threaded to being any
degree of multithreaded.)
--

     Key fingerprint = EB65 70AA 55C0 33AA 2E5A  5B59 42E9 9326 B16C F7F3
PGP Public Key Server: http://www.keyserver.net

Chiou, Zi-Wei
Computer Graphics and Geometry Modeling Laboratory,
Computer Science and Information Engineering Department,
National Chiao-Tong University, Taiwan

<url:http://www.csie.nctu.edu.tw/~jwchiu>
ICQ Number: 86384491

InterVideo, Inc.

TEL: +886-3-5750828 ext.125
FAX: +886-3-5750829
Address: 13F-1, No.6, Lane 99, Rd. Puding, Hsinchu City, Taiwan.

2. Stripping ^M off ftp, binary transfered files

3. Will using C++ strings be MT-safe and re-entrant ?

4. msgget() does not work.(Invalid system call error)

5. : When is a function mt-safe ?

6. New User - Configuring LILO

7. 'malloc' and 'free' is MT-safe in linux ?

8. 1.2.5 & 1.2.7 crash

9. MT-safe kernel module coding question

10. In what way is dup2() not MT-SAFE?

11. LDAP library MT-Safe?

12. MT-Safe

13. Any MT-safe regex code available?