🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

fork or pthread_create?

Started by
3 comments, last by Ramsess 17 years ago
was just wondering what opinions anyone might have on which is better to use for creating a thread. Like, one might be obsolete/unsupported now. Sorry, if this starts some kind of war but I haven't really programmed for almost 2 years. I've done it both ways and just want to know what "industry standard" might be.
------------------------------Piggies, I need more piggies![pig][pig][pig][pig][pig][pig]------------------------------Do not invoke the wrath of the Irken elite. [flaming]
Advertisement
Fork doesn't create a thread, it creates a new process. Processes don't share memory, threads do. If you need memory sharing, use threads. Otherwise, fork is probably better because you can't accidentally corrupt shared memory.

However, if you want to port your software to Windows eventually use threads. I have heard that process creation is far more expensive on Windows than Linux, so forking* isn't really a good option.

* That is to say: the Windows equivalent of forking.
Just a quick note: on Linux (and only on Linux), threads are processes that happen to share data, because spawning processes on Linux is extremely fast, thanks to copy-on-write shared pages. On most other systems, however, threads aren't processes, as rip-off explained.
Thank you both. I did not realize that about fork. I also have not used it in aobut 4 years. Since my code is being written from the start for both linux and windows I will be useing pthread_create.

P.S. I will undoutedly be back when I have mutex and semaphore issues! :(
------------------------------Piggies, I need more piggies![pig][pig][pig][pig][pig][pig]------------------------------Do not invoke the wrath of the Irken elite. [flaming]
threads on one process have own stack and share data and code segments.
process has all then own.

Thread switching is more faster. But older system has problem with thread, run all thread on same processor then process is run, so it's noce improve perfomance and make task more complexy.

This topic is closed to new replies.

Advertisement