Warning: Creating default object from empty value in /home/janeve/public_html/modules/mod_jshareeasy/mod_jshareeasy.php on line 42

Native vs Green threads

Understanding a multi-threaded program have always been a wild goose chase for many programmers. There are always many aspects to consider when writing a multi-threaded program.

Green threads vs Native Threads

The difference between green threads vs native threads is something that programmers may be unaware of. Both are mechanisms are ways of achieving a "multi-threaded program". It is the compiler / interpreter variants that usually implements green or native threads.

Native threads uses the operating systems threading capability to execute multi-threaded programs on the other hand, the green threads emulates the multi-threading without using the underlying capabilities of the OS. Green threads are also known as "Cooperative Threading" where each processes co-operate with each other to emulate a multi-threaded environment.

Execution in a multi-core machines

Another advantage of native threads is that multiple processes would execute in parallel in a multi-core machine. On the other hand, green threads are executed on a single core the entire time and it is the VM that gives a multi-threading notion. So actually there is only singe executing in case of green threads.

Process Scheduling

Native threads uses OS scheduling algorithm. Modern day OSes support pre-emptive scheduling. Green threads can use any kind of scheduling algorithm.

Synchronization and Resource sharing

Native threads usually have complicated synchronization and resource sharing. Multiple processes would require kernel level locks for synchronization. Synchronizations are pretty easier in case of green threads.

Warning: Creating default object from empty value in /home/janeve/public_html/modules/mod_jshareeasy/mod_jshareeasy.php on line 42