how2 port MULTITHREADED windows apps to Linux

how2 port MULTITHREADED windows apps to Linux

Post by Brian Wheel » Tue, 18 Nov 1997 04:00:00





Quote:> I have a -multithreaded- application that currently runs on NT, Win 98,
> and OS/2.  I would like to port it to Linux but am not familiar with
> the Linux (or Unix) implementation of multitasking.  I can see that
> a "child process" can be launched.  But can I launch another thread of
> execution that has both read and write access to the parent process's
> memory and file handles?

There's two ways to do it:
        fork (to fire off a child), which you've already discovered.  and
pthreads (POSIX Threads), which are threading like you're mostly familiar
with.  Pthreads is available for pretty much all unixes which support
threading, and many non-unixes as well.  The linux implementation is
linuxthreads, and is available via most distributions.  As a side note,
at the system level, linux provides a "clone" system call which is the
implementation for linuxthreads *and* fork.

Quote:

> General Question: Can I implement windows style multitasking on top of
> Linux?

        Oh, you  mean so it crashes? :)  J/K.  You're not wanting "windows
style multitasking", you're actually wanting multithreading (which was
*not* created by microsoft).

Quote:

> Particular Question: Can I suppress Linux's "copy on write" approach
> to forking?

        Nope, and you don't want to, since it is an efficiency boost.  in
multithreaded apps, the shared pages aren't CoW, so no problem.

Quote:

> TIA

What kind of app is it?

Brian Wheeler

 
 
 

how2 port MULTITHREADED windows apps to Linux

Post by Jon Duringe » Tue, 18 Nov 1997 04:00:00


has anyone done multithreading on Linux?  can it be done?

i'm using Red Hat Linux 4.2 and want to test multithreading.  The
code described in the man page for "clone" ("man clone") does not
compile; there are errors in one of the include files.  even if it
compiled, the man page states that it this api does not work.

i want to call "clone( 0 , 0 )" to see if it can be used for
multithreading.

Q1: has anyone tried multithreading on Linux?  did it work?

Q2: is the pthreads api or the linuxthreads api available on Linux?
these are not found in the man pages.  how can i get the info needed
to use them?

 
 
 

how2 port MULTITHREADED windows apps to Linux

Post by Daniel Joyc » Tue, 18 Nov 1997 04:00:00



> has anyone done multithreading on Linux?  can it be done?

> i'm using Red Hat Linux 4.2 and want to test multithreading.  The
> code described in the man page for "clone" ("man clone") does not
> compile; there are errors in one of the include files.  even if it
> compiled, the man page states that it this api does not work.

> i want to call "clone( 0 , 0 )" to see if it can be used for
> multithreading.

> Q1: has anyone tried multithreading on Linux?  did it work?

> Q2: is the pthreads api or the linuxthreads api available on Linux?
> these are not found in the man pages.  how can i get the info needed
> to use them?

        clone is a system call.
        There is a linux threads page, I don't remember where, but just search
the internet, or try the LDP project...

        sunsite.unc.edu/linux

        -Daniel

 
 
 

how2 port MULTITHREADED windows apps to Linux

Post by Steve Dunha » Wed, 19 Nov 1997 04:00:00



> has anyone done multithreading on Linux?  can it be done?

> i'm using Red Hat Linux 4.2 and want to test multithreading.  The
> code described in the man page for "clone" ("man clone") does not
> compile; there are errors in one of the include files.  even if it
> compiled, the man page states that it this api does not work.
> i want to call "clone( 0 , 0 )" to see if it can be used for
> multithreading.

You should use linuxthreads, or some other library.  clone() is not
really meant to be used directly (by mortals) - you would have to take
care of the stack and various other issues..

Quote:> Q1: has anyone tried multithreading on Linux?  did it work?

AOL's web server for Linux, released in beta form quite a while ago,
used LinuxThreads for threading.  There are

Quote:> Q2: is the pthreads api or the linuxthreads api available on Linux?
> these are not found in the man pages.  how can i get the info needed
> to use them?

The web?  (Yes, I know the trick is finding it.)  A search of Yahoo
for "Linux Thread" gives:

   http://linas.org/linux/threads-faq.html

The linux threads FAQ.

Have fun,

Steve

 
 
 

how2 port MULTITHREADED windows apps to Linux

Post by Mark Schaef » Wed, 19 Nov 1997 04:00:00


        I don't know exactly what "Windows style multithreading" is, but as
far as I know, most styles of multithreading include the following:
Memory sharing / visibility,
Process creation/destruction
InterThreadCommunication  (a.k.a. synchronization)

        Yes, you can do all these with Linux.  Linuxthreads (by name alone)
will work under Linux.  There are several P(POSIX)threads implementations
for Linux, try searching for pthreads and linux.  Actually, pthreads is
an OS-independent threading implementation, which should make it easier to
port to other unices.

        I haven't messed with clone(), but I know it's Linux specific, and
NOT portable.

Mark Schaefer

 
 
 

how2 port MULTITHREADED windows apps to Linux

Post by Mats Andtback » Thu, 20 Nov 1997 04:00:00



Quote:>I have a -multithreaded- application that currently runs on NT, Win 98,
>and OS/2.  I would like to port it to Linux

you're in for a rough ride. you're using something as beta as windows
98? you'll have to get as bleeding-edge on the Linux side to do this
right, and you might still be disappointed.

the Linux _kernel_ has support for multithreading, after a fashion. it
has a syscall named clone(), but if you think you need to use that
you're almost certainly wrong. on top of that syscall can be built, in
user space, support for a real threading model - this is normally done
in the C library.

the problem is that there's no real de facto standard for how such a
threading model should look in the Un*x world. a de jure standard has
been elected, POSIX threads, but it's not widely implemented, or even
completely implemented in Linux. if you want to learn how to use it,
buy the book about programming for it from O'Reilly and associates.

in order to use POSIX threads on Linux, you'll want a late-ish kernel
and glibc - this means Red Hat 5.0 or the latest development Debian
distribution. even then not all the parts are in place - threads on
Linux cannot share PIDs, and the signals we've got aren't really
thread-ready. maybe someday, but threads frankly don't seem to be a
big priority with many developers.

Quote:>but am not familiar with
>the Linux (or Unix) implementation of multitasking.  I can see that
>a "child process" can be launched.  But can I launch another thread of
>execution that has both read and write access to the parent process's
>memory and file handles?

that is in part what fork() *does*. if you want to _not_ have access
to the parent's file handles, pipes and so on, you have to disconnect
them after the fork(). memory areas i'm not so sure about, but they
too can be shared using SysV IPC mechanisms. one good book on this is
Stevens' Advanced Unix Programming, but not everything he explains
there is doable on Linux.

Quote:>General Question: Can I implement windows style multitasking on top of
>Linux?

probably, but it wouldn't be worth the pain. go with POSIX threads
unless you want to rewrite half of libc.

Quote:>Particular Question: Can I suppress Linux's "copy on write" approach
>to forking?

not that i know of, but why on earth would you want to? except if it's
the _copy_ part of CoW you want to suppress - if so, you want to learn
POSIX threading.
--
        "Pitiful, isn't it?"    - Marvin
 
 
 

how2 port MULTITHREADED windows apps to Linux

Post by Brett W. McCo » Thu, 20 Nov 1997 04:00:00



> I have a -multithreaded- application that currently runs on NT, Win 98,
> and OS/2.  I would like to port it to Linux but am not familiar with
> the Linux (or Unix) implementation of multitasking.  I can see that
> a "child process" can be launched.  But can I launch another thread of
> execution that has both read and write access to the parent process's
> memory and file handles?

You might want to take a look at the Linux Programmer's Guide -- one of
the many wonderful LDP documents.  It covers such arcane topics as message
queues, shared memory and semaphores.

Quote:> General Question: Can I implement windows style multitasking on top of
> Linux?

<shudder> You mean like using the callback functions that are never
directly called by your program?  Linux uses *real* pre-emptive
multitasking!  The thing you have to be careful of is synchronization and
file locking.  Again, take a look at the semaphores in the LDP manual.  It
gives some good examples.


Computer Operations Manager (Alpha Geek)   http://www.foiservices.com
FOI Services, Inc./DIOGENES                301-975-0110

 
 
 

how2 port MULTITHREADED windows apps to Linux

Post by Dave Cine » Sat, 22 Nov 1997 04:00:00



Quote:>I have a -multithreaded- application that currently runs on NT, Win 98,
>and OS/2.  I would like to port it to Linux but am not familiar with
>the Linux (or Unix) implementation of multitasking.  I can see that
>a "child process" can be launched.  But can I launch another thread of
>execution that has both read and write access to the parent process's
>memory and file handles?

Default libraries (and the linux kernel) do not thread. You need an
and add-on library to use them.

Quote:>General Question: Can I implement windows style multitasking on top of
>Linux?

God, I hope not.

Quote:>Particular Question: Can I suppress Linux's "copy on write" approach
>to forking?

forking is as forking does....

----------------------------------------------------------------------------

Dave 'Kill a Cop' Cinege  (aka Psychopath #3)  ---  Super Genius at Large
The Oklahoma City Federal building bombing -
Americas first response to government abuse

Go ahead, make my day...                http://www.psychosis.com/        

Libertarian Party 1-800-682-1776        http://www.lp.org/

 
 
 

1. Windows NT|2000 Linux 2.2 port (was Linux apps in win2000 port news!)

For about two months, I've been busy working away at the possibility of a
native NT microkernel version of a Linux server. It's definitely doable. I'm
collecting information at the moment. I was sort of hoping until I had some
code (typical bizarre project style), but since Interix have beat the OSS
community to the punch, I may as well announce it now.

I'm looking at making the linux server (subsystem) at least passingly
similar to the current 2.2 tree, so that changes could be merged in there
closer . The goal obviously is to run native Linux x86 and Alpha binaries
(depending on platform) without recompilation.

My current idea is for a %windir%\linux\... tree that contains a vmlinux.exe
and the standard linux file system standard and enough stuff to launch bash.
Once launched, the server launches linux images as normal. A
modification/complete re-write of umsdos would provide the file system (or
maybe just use ext2fs until this is a bit more of a reality). By making a
directX fbconsole layer, we could re-use the frame buffer console code as it
exists today. X would come (much) later, but again via the use of the XAA
layer in XFree86 4.0 (I know it doesn't yet exist, but I helped write the
early 3.9 stuff, so I know it does exist :-)

The native NT api is exceptionally well hidden and undocumented, but
NT/W2k's microkernel is as least as good as Mach in all respects (and memory
and thread management, it's significantly better), so a mklinux server port
wouldn't take more than a year with dedicated people.

 If anyone's interested please drop me a line. You'd need to have a compiler
and a passing knowledge of Windows NT/2000 to be useful at this stage. I'm
going to use Visual C++ until I can prove to myself that cygnus's (or other)
gcc under WIn32 can do the job. The reason for this is the header files,
which are vital to Win32 development.

Andrew

2. Solaris SMP?

3. debugging multithreaded RH6.2 linux apps w/ gdb

4. how many files are open ??

5. Need Info on porting MS-Windows app. to Unix (Linux).

6. NIS+ and auto_home, auto_master

7. Porting Dos/Windows apps to Linux/X using gnu

8. Oh no, I need a shit

9. Porting multithreaded programs to linux?

10. Q: Debugging a multithreaded app?

11. Multithreaded app and TCP/IP stack

12. single vs multithreaded apps

13. Debugging multithreaded apps