Linux-Development-Sys Digest #826, Volume #7 Fri, 5 May 00 20:13:17 EDT
Contents:
Re: Waiting on two threads (Kaz Kylheku)
Need to find my IP address (Doug Schulz)
Re: Need to find my IP address ("Jerry Williams Jr.")
Re: Need to find my IP address (Kaz Kylheku)
malloc more than the mem available ? (Olivier Spielmann)
Re: Real Time Programming in Linux (Erik de Castro Lopo)
Re: Need to find my IP address ("G. Roderick Singleton")
Re: A need for better insallation programs (Michael Uman)
Re: A need for better insallation programs ([EMAIL PROTECTED])
----------------------------------------------------------------------------
From: [EMAIL PROTECTED] (Kaz Kylheku)
Subject: Re: Waiting on two threads
Reply-To: [EMAIL PROTECTED]
Date: Fri, 05 May 2000 18:25:17 GMT
On 05 May 2000 08:46:04 -0400, Brian Lalor <[EMAIL PROTECTED]> wrote:
>
>I'm trying to write a program that spawns two threads and then waits for them
>to finish. The problem is that I don't know ahead of time which thread will
>finish first. As I understand the signaling methodology
>(pthread_cond_signal()), I can only wait on one signal at a time, and spin
>locking just sucks up CPU. Here's a basic layout of what I'm trying to do:
You misunderstand the purpose of condition variables. The purpose of a
condition variable is to delay the execution of a thread until a specific state
change occurs in the shared data that is protected by the mutex. The condition
itself doesn't encapsulate the state change.
A single condition can be used to wait on many different events; upon waking
up, the thread has to examine the shared data and figure out the reasons
why it may have been woken up and respond accordingly.
>typedef struct _mystruct_t {
Filescope identifiers, in both the ordinary as well as the struct/union/enum
tag namespace, that begin with a single underscore and a lower-case letter are
reserved. This declaration invokes undefined behavior.
> pthread_mutex_t mutex;
> pthread_cond_t cond;
>} mystruct_t;
>
>void send_file(void *ptr)
>{
> mystruct_t *a_struct;
> a_struct = (mystruct_t *)ptr;
>
> /* send data to server here */
>
> pthread_cond_signal(&(a_struct->cond));
You have forgotten to set the state of the shared data. Your struct
needs an additional member: ``int shutdown; '' which is initially
set to zero.
>}
>
>main ()
>{
> mystruct_t struct1, struct2;
>
> /* init mutexes and conds in structs */
>
> pthread_create(&writer1, NULL, (void *)&send_file, (void *)&struct1);
> pthread_create(&writer2, NULL, (void *)&send_file, (void *)&struct2);
>
> /**
> Now what?
> **/
>}
In this particular case, I would forget about the signalling and just use
pthread_join() on all of them.
If you don't want to use pthread_join(), you can simply wait on the condition
variable of each one in turn. Suppose that in the general case you had N
structs and N threads:
for (i = 0; i < N; i++) {
pthread_mutex_lock(&struct[i].mutex);
while (!struct[i].shutdown)
pthread_cond_wait(&struct[i].cond, &struct[i].mutex);
pthread_mutex_unlock(&struct[i].mutex);
}
Note that the call to pthread_cond_wait is bypassed for any threads which
already terminated. So suppose in the worst case, thread 0 takes 3 minutes to
shut down, but the rest only take a millisecond. So the first iteration of the
loop will wait 3 minutes. After waiting, it will just zip through the rest of
the threads and find their shutdown flags to already be non-zero. The
overall elapsed time of the loop is determined by the longest shutdown time.
>Its looking like I should wait on one of the conditional variables, test to
>see if the other's done (have a done_sending var in the struct), and wait on
Right, you need a flag.
>the second conditional if it is not; however, I'd really like to be notified
>when *either* thread is done first (arbitrarily), rather than taking the
>chance that I'll be waiting on the thread that's finished second.
Since your main thread has nothing important to do other than wait, it does
not matter what order it waits in.
If it's important for the thread to respond to terminations in a timely manner,
you need some alternate scheme.
You should give each of the threads a reference to a single mutex and condition
variable which is used for notifying the ``boss'' thread. You can do something
like this:
struct shutdown_notice {
int finished[NUM_THREADS];
pthread_mutex_t mutex;
pthread_cond_t cond;
};
You pass a pointer to one instance of this to each thread, and ensure that it
knows what position in the array belongs to it: perhaps using another
encapsulating structure:
struct thread_struct {
int my_position;
struct shutdown_notice *sn;
/* .. other thread argument data .. */
};
To indicate completion, a thread simply does this:
pthread_mutex_lock(&my_struct->sn->mutex);
my_struct->sn->finished[my_struct->my_position] = 1;
pthread_mutex_unlock(&my_struct->sn->mutex);
pthread_cond_broadcast(&my_struct->sn->cond);
The boss thread just waits on the condition and then iterates over the
finished[] array to see who is done.
--
#exclude <windows.h>
------------------------------
Crossposted-To: comp.os.linux.development.apps,comp.os.linux,comp.os.linux.misc
Date: Fri, 5 May 2000 11:46:48 -0700
From: Doug Schulz <[EMAIL PROTECTED]>
Subject: Need to find my IP address
I have a sockets program an need to find the IP address of the machine
the program is being run from so I can bind the socket to the correct
address/port. I have tried using gethostname coupled with gethostbyname
and I can only get 127.0.0.1 (localhost address). I want to find the
actual IP address of the machine. Is there a way of doing this. Any
help would be great.
FYI this is a UDP app.
Thanks,
Doug
------------------------------
From: "Jerry Williams Jr." <[EMAIL PROTECTED]>
Crossposted-To: comp.os.linux.development.apps,comp.os.linux,comp.os.linux.misc
Subject: Re: Need to find my IP address
Date: Fri, 05 May 2000 18:55:32 GMT
Doug Schulz wrote:
>
> I have a sockets program an need to find the IP address of the machine
> the program is being run from so I can bind the socket to the correct
> address/port. I have tried using gethostname coupled with gethostbyname
> and I can only get 127.0.0.1 (localhost address). I want to find the
> actual IP address of the machine. Is there a way of doing this. Any
> help would be great.
>
> FYI this is a UDP app.
>
> Thanks,
>
> Doug
ifconfig
Jerry
------------------------------
From: [EMAIL PROTECTED] (Kaz Kylheku)
Crossposted-To: comp.os.linux.development.apps,comp.os.linux,comp.os.linux.misc
Subject: Re: Need to find my IP address
Reply-To: [EMAIL PROTECTED]
Date: Fri, 05 May 2000 19:13:56 GMT
On Fri, 5 May 2000 11:46:48 -0700 , Doug Schulz <[EMAIL PROTECTED]> wrote:
>I have a sockets program an need to find the IP address of the machine
>the program is being run from so I can bind the socket to the correct
>address/port. I have tried using gethostname coupled with gethostbyname
>and I can only get 127.0.0.1 (localhost address). I want to find the
>actual IP address of the machine. Is there a way of doing this. Any
>help would be great.
Gethostname will pull your your machine's name, and gethostbyname will
just retrieve whatever IP address is in your /etc/hosts file associated
with your host name.
So one solution is to have the correct contents in /etc/hosts, such
as:
127.0.0.1 localhost localhost
192.168.0.1 myhost.mydomain myhost
So if you do a gethostbyname on "localhost" you get the loopback address,
and if you do the lookup on "myhost", you should get the real IP
address 192.168.0.1. Of course, this won't work if the host has
a dynamically assigned IP address.
The long answer is that a machine may have many IP addresses. The address
127.0.0.1 is just as valid as any other. It's just not reachable from
the outside network.
In the general case, a machine may not only have multiple adapters that
sit on multiple networks, and are known by a different IP in each of these
networks, but a single network adapter may also have multiple IP
addresses (you've heard of IP aliasing, right?)
So there is no right answer to the question ``what is my IP address'', because
the right question is ``what are all my IP addresses?''. From all the IP
addresses, it's not easily possible to determine which is the most important
one, or the relevant one in a given context.
Intelligently written networking software does not care what its IP address is.
Your IP address is, effectively, whatever a given peer knows you to be. For
example, on a certain machine at work, I have the IP address 10.1.3.9. But
this address is meaningless to the Internet beyond the firewall, which sees the
same machine as a different address.
If I wrote a program to retrieve the address "10.1.3.9" and sent that address
to the outside world, that would be a programming bug, because that address
makes no sense in that context.
The BSD derived ``talk'' utility would fail most of the time precisely because
it naively tries to retrieve the local IP by doing a gethostbyname lookup and
then sends this IP to the remote host. A lot of the time, this braindamaged
program would end up sending something meaningless like "127.0.0.1", or
some static intranet IP, so you would get an error message when trying to
talk, or reply to a talk. (Has this been fixed?)
--
#exclude <windows.h>
------------------------------
Date: Fri, 05 May 2000 13:12:21 -0700
From: Olivier Spielmann <[EMAIL PROTECTED]>
Subject: malloc more than the mem available ?
Hi,
I am using RH 5.2 kernel 2.2.3. My amount of RAM is 128 MB and my swap
space is 128 MB. I have just written a small application to understand
better the malloc behaviour.
The application allocate with malloc 2 times 200 MB. How come this is
possible because my amount of RAM and swap is only 256 MB ? How is the
kernel managing that kind of cases ? What happens if I fill this 2
pointing memory spaces ?
Thanks
--
===========================================================================================
Olivier Spielmann
Communication Systems EPFL student (Switzerland)
Intern (thesis internship)
3Com Corporation
5400 Bayfront Plaza
M/S: 3219
Santa Clara, CA 95052-8145
Work: ++1 (408) 326 6304
Fax: ++1 (408) 326 8188
------------------------------
From: Erik de Castro Lopo <[EMAIL PROTECTED]>
Subject: Re: Real Time Programming in Linux
Date: Fri, 05 May 2000 21:28:05 +0000
Simon Wakley wrote:
>
> I am porting a robotic controller system to linux, and my program has to
> spew out data over the parallel port every 20ms. It does not have to be
> exactly every 20ms, but it must average exactly that. I have tried
> starting a high priority thread from my XWindows app, but it does not
> run at very high priority and gets blocked when I do some windows
> intensive activity.
>
> Does anyone know about programming in real time for linux or how you go
> about that.?? I had been handling this with a separate processor, but
> would like to integrate it all into Linux for speed of operation.
For soft realtime (which should be sufficient for you purposes) look at
sched_setscheduler() (read the man page).
There are also firm realtime and hard realtime extensions for Linux.
http://www.ittc.ukans.edu/kurt/ (firm)
http://www.rtlinux.com/ (hard)
> (BTW the parallel port device driver that talks to the H/W is in C.
> would it be a lot faster in assembler if that can be done???)
Probably not.
Erik
--
+-------------------------------------------------+
Erik de Castro Lopo [EMAIL PROTECTED]
+-------------------------------------------------+
"Testing can prove the presence of bugs, but never their absence."
-- Edsger Dijkstra
------------------------------
From: "G. Roderick Singleton" <[EMAIL PROTECTED]>
Crossposted-To: comp.os.linux.development.apps,comp.os.linux,comp.os.linux.misc
Subject: Re: Need to find my IP address
Date: Fri, 05 May 2000 23:19:38 GMT
Doug Schulz wrote:
>
> I have a sockets program an need to find the IP address of the machine
> the program is being run from so I can bind the socket to the correct
> address/port. I have tried using gethostname coupled with gethostbyname
> and I can only get 127.0.0.1 (localhost address). I want to find the
> actual IP address of the machine. Is there a way of doing this. Any
> help would be great.
>
> FYI this is a UDP app.
>
> Thanks,
>
> Doug
man -k inet
--
________________________________________________________________________________
G. Roderick Singleton, <[EMAIL PROTECTED]> PATH tech,
71 Underhill Drive, Unit 159, Toronto, ON M3A 2J8
Voice : 416-452-4583 Fax: 416-452-0036 Toll Free: 1-888-354-PATH
________________________________________________________________________________
*** Notice To Bulk Emailers: Attention! Pursuant to US Code, Title 47,
Chapter 5, Subchapter II, 227, any & all unsolicited commercial e-mail
sent to this address is subject to a download and archival fee in the
amount of the $1500 US and copies will be forwarded to domain
administrators. Emailing denotes acceptance of said terms!
------------------------------
Date: Fri, 05 May 2000 23:16:39 +0000
From: Michael Uman <[EMAIL PROTECTED]>
Subject: Re: A need for better insallation programs
Ingvar Langlet wrote:
> Stockholm 2000-05-02
>
> Dear Linux community,
>
> A publicity disaster and the need for better installation programs.
> -------------------------------------------------------------------
>
> With the Gnome and Kde Linux offer users coming from theDOS-M$-Win-
> dow$.* GUI-s that must be as easy and convenient for them as M$ Win-
> dow$.* GUI. Even if some components of the Gnome and Kde GUI-s not yet
> can be considered as stable by Linux standrads I think they are less
> beta than M$ Window$.* (I myself prefer to work in conslole mode when-
> ever possible.)
>
> In Sweden journalists for a science program, without any computer ex-
> perience beside of using preloaded Apple or/and M$ Window$.* systems
> recenly thought they would demonstrate how Linux can be downloaded
> from the net. The system they did chose was intended to run in a DOS
> partition -- becuse they considered partitioning a hard disk be a too
> daunting task for them.
>
> They downloaded the system to the hard disk of an empty laptop, went
> on air -- and then just pressed <enter>. Nothing happened. This was
> broadcasted and claimed to prove that Linux is too dificult to install
> for general users.
>
> When I had heard this I wrote to them and told them that their way to
> install Linux must fail and informed them that Caldera's Open-Linux is
> very easy to install. (My own system is Slackware.) They mamaged to
> install Open-Linux. However, they did not find out how to smoothly
> install the applications too.
>
> Then they claimed that their failure to set up the applications proved
> that it must be several years before Linux can be run by the general
> public. They also cracked a joke that Linux must be a penguin made of
> a feather and played a lampoon against Linux.
>
> That was a publicity disaster for Linux. Was it a publicity stunt
> planted by Micro$oft? Or was it sheer stupidity? Once upon the time
> my parents told me that whenever evil and stupidity are the alterna-
> tives, stupidity is the most likely explanation. I believe these stu-
> pid journalists come to hate Linux because it had tempted them to in
> public make fools of themselves.
>
> The conclusion from above must be that Linux badly needs installation
> programs, like Micro$oft's installation and setup programs, who would
> make it easy -- even for the most stupid science journalists -- to
> smoothly set up a Linux system they can run and then smoothly load
> applications to the system. I myself cannot possibly find time to
> learn enough about programming to write these programs. Are there some
> out there who would like to write these badly needed installation pro-
> grams? I am
>
> Sincerely Yours
>
> Ingvar Langlet
>
> Forsen 8, 123 72 Farsta, Sweden
>
> Telephones: +46 08 60 555 06 or +46 150 664 049
>
> e-mail: [EMAIL PROTECTED]
Sounds to me like a bunch of idiots got together to prove how dumb they
are. Doesn't sound like scientific testing at all. I installed my
Mandrake Linux distro on three machines, each install was flawless. Each
machine has different CPU and different memory and different display. The
auto-install process was excellent, many times faster than Win98 or WinNT
install.
I don't know who is complaining about installers. Obviously this test was
not performed in a scientific manner. I know for a fact that most
installers on Windows don't do much version checking {unless the script
programmer knew a little bit about something, which most script writers
don't}. Look at the problem my company is having concerning the version
of WinASPI. Microsoft dropped the ball big time with that DLL. Originally
MS supported it in Win3.1 and Win95... Then they dropped it from WinNT,
and added it back in Win98.... TOTAL LUNACY! Now the installer must check
if the DLL is available, what version, if the version is not right prompt
user to install correct version. Microsoft suffers from many problems
with their installers. To say this is a problem with Linux is pure
lunacy. People who know nothing should keep their traps shut unless they
have a valid question.
I use KPackage on my Distro which is a class-act installer. It recognizes
version problems before installing, preventing users from installing
software which will mess up operation of existing applications. Very
smart indeed. I haven't seen an installer on Windows which has the power
and ease of use of RPMS.
Also, custom installers are cool. The Corel Wordperfect installer is also
very slick and graphical. The installer is an application, not a function
of the OS. As much as the folks at Microsoft want the 'dummies' in the
computer world to believe, the OS is responsible for Memory, I/O, and CPU
control. To say that the installer makes Windows bad is sheer idiocy.
Windows as an OS is a bad example of OS principles. I'm sure there are
Microsofties who actually believe that a WordProcessor is a part of the
OS. A calendar program is a part of the OS. A notepad is a part of the
OS... Really!?!?
Linux will rule the world!
--
//-------------------------------------------------------
// PROGRAMMER : Michael A. Uman
// PROJECT : Email Signature
// TITLE : Senior Software Engineer
// EMAIL : mailto:[EMAIL PROTECTED]
//-------------------------------------------------------
------------------------------
From: [EMAIL PROTECTED]
Subject: Re: A need for better insallation programs
Date: Sat, 06 May 2000 00:01:53 GMT
Michael Uman <[EMAIL PROTECTED]> wrote:
[...]
>> In Sweden journalists for a science program, without any computer ex-
>> perience beside of using preloaded Apple or/and M$ Window$.* systems
>> recenly thought they would demonstrate how Linux can be downloaded
>> from the net. The system they did chose was intended to run in a DOS
>> partition -- becuse they considered partitioning a hard disk be a too
>> daunting task for them.
[...]
> Sounds to me like a bunch of idiots got together to prove how dumb they
> are. Doesn't sound like scientific testing at all. I installed my
> Mandrake Linux distro on three machines, each install was flawless. Each
> machine has different CPU and different memory and different display. The
> auto-install process was excellent, many times faster than Win98 or WinNT
> install.
The key phrase in all of this is "preloaded Apple or/and M$ Window$.*
systems" Contrary to popular belief, _NO_ operating system is easy to
install without a reasonable amount of knowledge. Many windows users
are incapable of reinstalling windows given an unparitioned hard
drive, the windows cd, and a working machine to hand-roll a boot disk
on. There's nothing wrong with that, but obviously installing linux
yourself is more difficult than letting someone at the factory install
windows. Hell, installing a _toaster_ yourself is more difficult than
having someone else plug it in.
Every time I hear comparisions like these, I'm reminded of an early
review of linux I saw in a PC-centric magazine. It procalimed
something along the lines of "while it's a powerful operating system,
it forced us to spend too much time interacting with the command
line." The author, never having used a non-ms operating system
apparantly, mistakenly equated /bin/sh with command.com.
--
Matt Gauthier <[EMAIL PROTECTED]>
------------------------------
** FOR YOUR REFERENCE **
The service address, to which questions about the list itself and requests
to be added to or deleted from it should be directed, is:
Internet: [EMAIL PROTECTED]
You can send mail to the entire list (and comp.os.linux.development.system) via:
Internet: [EMAIL PROTECTED]
Linux may be obtained via one of these FTP sites:
ftp.funet.fi pub/Linux
tsx-11.mit.edu pub/linux
sunsite.unc.edu pub/Linux
End of Linux-Development-System Digest
******************************