Unoffical empeg BBS

Quick Links: Empeg FAQ | RioCar.Org | Hijack | BigDisk Builder | jEmplode | emphatic
Repairs: Repairs

Topic Options
#66824 - 04/02/2002 15:17 pThreads on the empeg
wfaulk
carpal tunnel

Registered: 25/12/2000
Posts: 16706
Loc: Raleigh, NC US
So I thought it would be useful for empegVNC to be multithreaded (for purposes not yet revealed ). It was easy enough to implement initially using pThreads. However, when I ran it on the empeg, I noticed that it actually created multiple processes. This is remarkably annoying, as I was using threads solely to avoid creating the overhead of multiple processes (and, maybe, to control the scheduling of the process). Am I doing something dramatically wrong (I'm using only pthread_create() and pthread_detach() from the pThreads API at this point) or is this the expected behavior of pThreads on a Linux (or arm-Linux?) platform? If it's expected, is there a more lightweight thread API I should be using?
_________________________
Bitt Faulk

Top
#66825 - 04/02/2002 15:35 Re: pThreads on the empeg [Re: wfaulk]
mlord
carpal tunnel

Registered: 29/08/2000
Posts: 14493
Loc: Canada
I'm not 100% knowledgeable about pthreads-on-linux, but the Linux kernel does NOT distinguish between threads and processes. They are all treated the same internally, except when created. So, one can create lightweight threads (eg. kftpd, khttpd), but they will appear to be ordinary processes when queried.

You might be able to distinguish between them by looking that the process flags, possibly available somewhere under /proc/$pid

-ml

Top
#66826 - 04/02/2002 15:40 Re: pThreads on the empeg [Re: mlord]
wfaulk
carpal tunnel

Registered: 25/12/2000
Posts: 16706
Loc: Raleigh, NC US
So it's possible that they're still LWPs, but they're each assigned full-on PIDs by the kernel anyway for internal reasons? I'll take a look at the /proc structure to see if it provides any info. Thanks.
_________________________
Bitt Faulk

Top
#66827 - 04/02/2002 17:21 Re: pThreads on the empeg [Re: wfaulk]
tman
carpal tunnel

Registered: 24/12/2001
Posts: 5528
pthreads uses the clone system call to work. The extra processes are actually the same as the main program. It just represents each thread.

- Trevor

Top
#66828 - 05/02/2002 02:34 Re: pThreads on the empeg [Re: wfaulk]
bonzi
pooh-bah

Registered: 13/09/1999
Posts: 2401
Loc: Croatia
Well, if they share the same address space (without explicitly attaching to shared memory segments) then they would appear to be 'lightweight'...
_________________________
Dragi "Bonzi" Raos Q#5196 MkII #080000376, 18GB green MkIIa #040103247, 60GB blue

Top
#66829 - 05/02/2002 11:45 Re: pThreads on the empeg [Re: wfaulk]
fvgestel
old hand

Registered: 12/08/2000
Posts: 702
Loc: Netherlands
I don't think threads will speed up your app or lower it's resource hunger. Forked processes also share the same readonly memory-regions and are created as fast as threads. When running displayserver in threaded mode, I saw an increase in memory usage, due to the extra thread libs. Another disadvantage is the fact that your complete application will die if an unexpected error occurs in one of your threads


Edited by fvgestel (05/02/2002 11:52)
_________________________
Frank van Gestel

Top
#66830 - 05/02/2002 13:13 Re: pThreads on the empeg [Re: fvgestel]
wfaulk
carpal tunnel

Registered: 25/12/2000
Posts: 16706
Loc: Raleigh, NC US
It looks like you may be right. Linux's thread implementation seems to leave something to be desired. I'll do a little more research before reverting to separate processes, but, damn, I was looking to put that pthreads book I bought years ago finally to some good use.
_________________________
Bitt Faulk

Top
#66831 - 06/02/2002 06:25 Re: pThreads on the empeg [Re: wfaulk]
altman
carpal tunnel

Registered: 19/05/1999
Posts: 3457
Loc: Palo Alto, CA
The threads do share the same memory space (we use pthreads in the player) and this helps quite a bit on the strongarm - no D-cache flush (an expensive operation on the strongarm) is required when context switching to another process/thread with the same memory map.

Hugo

Top
#66832 - 07/02/2002 08:10 Re: pThreads on the empeg [Re: altman]
fvgestel
old hand

Registered: 12/08/2000
Posts: 702
Loc: Netherlands
I was under the assumption that every thread would use it's own stack, which is default 8k, which is the same for normal processes. If I look at the difference in size however, I see a major difference :
output from top :

PID USER PRI NI SIZE RSS SHARE STAT LIB %CPU %MEM TIME COMMAND
26 root 0 0 96 96 64 S 0 0.0 0.8 0:00 ds2
321 root 0 0 312 312 236 S 0 0.0 2.8 0:00 displayserve


threaded = 312-236 = 76 k
mprocess = 96 - 64 = 32 k

running the free command before and after starting threaded ds shows a memory increase of 92 k, which would indicate two stacks (8k+8k) are used, as there are two threads running after startup.
Context-switches are probably a lot more efficient using threads, but aren't an issue when another realtime app is running, which will always cause efficient context-switching hard to guarantee.

I'll try to experiment some more; I ran these tests with a very old version of displayserver and I will try to put some load on the threads/processes.
I was able to open 10+ applets concurrently with the player app in mprocess mode, while in threaded mode it would shut down the complete app when trying it. Probably also caused by the real-time nature of the player app. It probably also happens in the mprocess-version, but isn't noticed as only the last process is terminated...
_________________________
Frank van Gestel

Top