LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-09-2009, 08:05 PM   #16
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled

Quote:
So you're telling me theres no possible way to do multitasking without forking?
No! That's not at all what wje_lq is saying!
Quote:
You have either to fork() or to use threads of some sort. Unless you have special requirements, fork() is the way to go.
Did you catch the "or" in there?

He and I disagree: I suggested "unless you have special requirements, 'pthread_create()' is the way to go". But there are pros and cons on either side, and there's no "right" or "wrong" answer. Wje_lq correctly points out some very good reasons for preferring "fork" over "pthread_create()".

SUGGESTION:
Look up "threads" and "processes" in Wikipedia (or something like that).

In general, a "process" is what you get from "fork()".

In general, a "thread" is what you get from "pthread_create()".

There are many different kinds of "concurrency", and lots of subtle (and not-so-subtle) issues involved.

BOTTOM LINE:
"fork()" and "pthread_create()" are different .. and there's a place for both in your toolbox!

Please post back with more questions once you've had a chance to look at the distinction between "process" and "thread".

Last edited by paulsm4; 03-09-2009 at 08:07 PM.
 
Old 03-09-2009, 09:58 PM   #17
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by the_ultimate_samurai View Post
i have actually had this same problem. i cant figure out the advantages of forking opposed to multithreading.

the things mentioned above seem like they could be just as easily done with a thread...so why fork?
If you want to run the same function in parallel, the function should be thread-safe, i.e., for example, it shouldn't use global/static data.

When forking you do not have the limitation, i.e. you have a copy of both data and code, and each code body deals with its own global/static data.

This is my understanding.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
piping /forking geminigal Programming 3 04-10-2005 09:49 PM
Linux Forking? linuxmania Linux - Distributions 3 04-07-2005 12:59 PM
Forking under Slackware 10 DD32 Slackware 10 07-16-2004 03:30 PM
Forking is very slow jspenguin Linux - General 2 05-29-2004 02:03 PM
Help! Forking errors! strider Linux - General 10 04-25-2002 12:22 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:32 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration