Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize Cooperative Program in Golang and .NET

2025-04-08 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article will explain in detail how to implement the collaborative process between Golang and .NET. The content of the article is of high quality, so the editor will share it with you for reference. I hope you will have some understanding of the relevant knowledge after reading this article.

Golang goroutine

Implement the following code to explicitly specify that the compiler dispatches goroutine to run on multiple CPU.

Import "runtime"... runtime.GOMAXPROCS (4)

There are several functions in the PS:runtime package that handle goroutine

Function

Description

Goexit

Exits the currently executed goroutine, but the defer function continues to call the

Gosched

Relinquish the execution rights of the current goroutine, and the scheduler arranges other waiting tasks to run and resume execution from that location at some point next time.

NumCPU

Returns the number of CPU cores

NumGoroutine

Returns the total number of tasks being executed and queued

GOMAXPROCS

Used to set the maximum number of CPU cores that can be calculated in parallel and return the previous value

Several concepts of Go scheduling:

M: kernel thread

G:go routine, the smallest logical unit of concurrency, created by programmers

P: processor, execution G context, each P maintains a local go routine queue

In addition to having a local go routine queue for each P, there is a global go routine queue.

Specific scheduling principles:

The number of P in initialization is determined by GOMAXPROCS

All we have to do is add G.

If the number of G exceeds the processing capacity of M, and there is a spare P, runtime will automatically create a new M

M can only work after getting P, and the order of G is: local queue > global queue > other P queues. If all queues do not have available GMagneM, they will return P and go to sleep.

When it comes to .NET 's Task model, it's more or less the same as Golang's collaborative process:

M = Thread

G = Task

P = Processor

On how to achieve cooperation between Golang and .NET to share here, I hope that the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report