第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

線程從 Java 開始

線程從 Java 開始

溫溫醬 2021-11-01 17:34:05
我如何將下面的代碼轉(zhuǎn)換為Go,您可以在下面看到我的嘗試,但是因?yàn)槲艺诘却粋€(gè)鍵輸入,該代碼將始終返回20000java 將輸出不同結(jié)果的位置。我知道兩者都有競(jìng)爭(zhēng)條件,但我只想知道翻譯。爪哇public class Counting {    public static void main(String[] args) throws InterruptedException {      class Counter {        private int count = 0;        public void increment() { ++count; }        public int getCount() { return count; }      }    final Counter counter = new Counter();    class CountingThread extends Thread {        public void run() {            for(int x = 0; x < 10000; ++x)                counter.increment();            }    }    CountingThread t1 = new CountingThread();    CountingThread t2 = new CountingThread();    t1.start(); t2.start();    t1.join(); t2.join();    System.out.println(counter.getCount());  }}這是我的嘗試:import (  "fmt")type Counting struct {  count int}var counter = Counting{}func (c *Counting) increment() {  c.count++}func (c *Counting) getCount() int {  return c.count}func CountingThread() {  for i := 0; i < 10000; i++ {    counter.increment()  }}func main() {  go CountingThread()  go CountingThread()  var input string  fmt.Scanln(&input)  fmt.Println(counter.getCount())}
查看完整描述

1 回答

  • 1 回答
  • 0 關(guān)注
  • 132 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)