草庐IT

c++ - Linux C++ : Does a return from main() cause a multithreaded app to terminate?

这个问题似乎是重复的,但我找不到。如果我错过了之前的问题,我们深表歉意。在我最有经验的Java中,如果您的main()fork一个线程并立即返回,该进程将继续运行,直到该进程中的所有(非守护进程)线程都已停止。在C++中,情况似乎并非如此——只要主线程返回,进程就会终止,而其他线程仍在运行。对于我当前的应用程序,可以通过应用pthread_join()轻松解决这个问题,但我想知道是什么原因导致了这种行为。这个编译器(gcc)是特定的、pthreads特定的,还是在大多数/所有已实现C++的平台之间共享的行为?这种行为是否可以在pthreads中配置(我已经在pthread_attr_*

c++ - Linux C++ : Does a return from main() cause a multithreaded app to terminate?

这个问题似乎是重复的,但我找不到。如果我错过了之前的问题,我们深表歉意。在我最有经验的Java中,如果您的main()fork一个线程并立即返回,该进程将继续运行,直到该进程中的所有(非守护进程)线程都已停止。在C++中,情况似乎并非如此——只要主线程返回,进程就会终止,而其他线程仍在运行。对于我当前的应用程序,可以通过应用pthread_join()轻松解决这个问题,但我想知道是什么原因导致了这种行为。这个编译器(gcc)是特定的、pthreads特定的,还是在大多数/所有已实现C++的平台之间共享的行为?这种行为是否可以在pthreads中配置(我已经在pthread_attr_*

c - 如果我要用汇编编写程序,这个 HelloWorld 汇编代码的哪些部分是必不可少的?

我有这个简短的helloworld程序:#includestaticconstchar*msg="Helloworld";intmain(){printf("%s\n",msg);return0;}我用gcc编译成如下汇编代码:.file"hello_world.c".section.rodata.LC0:.string"Helloworld".data.align4.typemsg,@object.sizemsg,4msg:.long.LC0.text.globlmain.typemain,@functionmain:.LFB0:.cfi_startprocpushl%ebp.cfi

c - 如果我要用汇编编写程序,这个 HelloWorld 汇编代码的哪些部分是必不可少的?

我有这个简短的helloworld程序:#includestaticconstchar*msg="Helloworld";intmain(){printf("%s\n",msg);return0;}我用gcc编译成如下汇编代码:.file"hello_world.c".section.rodata.LC0:.string"Helloworld".data.align4.typemsg,@object.sizemsg,4msg:.long.LC0.text.globlmain.typemain,@functionmain:.LFB0:.cfi_startprocpushl%ebp.cfi

java - 线程 "main"java.lang.NoClassDefFoundError : org/apache/hadoop/util/PlatformName 中的异常

我知道有很多关于此异常的帖子,但我无法解决此问题。我认为必须编辑类路径才能解决它。我正在尝试在hadoop基础设施中运行一个名为DistMap的程序。这是我遇到的错误。Causedby:java.lang.ClassNotFoundException:org.apache.hadoop.util.PlatformNameatjava.net.URLClassLoader$1.run(URLClassLoader.java:202)atjava.security.AccessController.doPrivileged(NativeMethod)atjava.net.URLClassL

java - 线程 "main"java.lang.NoClassDefFoundError : org/apache/hadoop/util/PlatformName 中的异常

我知道有很多关于此异常的帖子,但我无法解决此问题。我认为必须编辑类路径才能解决它。我正在尝试在hadoop基础设施中运行一个名为DistMap的程序。这是我遇到的错误。Causedby:java.lang.ClassNotFoundException:org.apache.hadoop.util.PlatformNameatjava.net.URLClassLoader$1.run(URLClassLoader.java:202)atjava.security.AccessController.doPrivileged(NativeMethod)atjava.net.URLClassL

c - Getopt 不包括在内?函数 ‘getopt’ 的隐式声明

我想使用getopt,但它行不通。它给了我gcc-g-Wall-std=c99-ftrapv-O2-Werror-Wshadow-Wundef-save-temps-Werror-implicit-function-declaration-c-osrc/main.osrc/main.csrc/main.c:Infunction‘main’:src/main.c:13:2:error:implicitdeclarationoffunction‘getopt’[-Werror=implicit-function-declaration]src/main.c:23:14:error:‘opt

c - Getopt 不包括在内?函数 ‘getopt’ 的隐式声明

我想使用getopt,但它行不通。它给了我gcc-g-Wall-std=c99-ftrapv-O2-Werror-Wshadow-Wundef-save-temps-Werror-implicit-function-declaration-c-osrc/main.osrc/main.csrc/main.c:Infunction‘main’:src/main.c:13:2:error:implicitdeclarationoffunction‘getopt’[-Werror=implicit-function-declaration]src/main.c:23:14:error:‘opt

c - 为什么没有 return 语句的 main 函数返回值 12?

我编写了一个打印表格的程序。我没有在main函数中包含return语法,但是每当我输入echo$?它显示12。我的源代码:#includeintmain(void){intans,i,n;printf("entertheno.:");scanf("%d",&n);for(i=1;i我没有写return12,但是每次执行程序还是返回12。谢谢。 最佳答案 正如swegi所说,它是未定义的行为。正如SteveJessop等人所说,它在C89之前是一个未指定的值,并在C99中指定(观察到的行为不符合C99)在大多数环境中实际发生的是最后一

c - 为什么没有 return 语句的 main 函数返回值 12?

我编写了一个打印表格的程序。我没有在main函数中包含return语法,但是每当我输入echo$?它显示12。我的源代码:#includeintmain(void){intans,i,n;printf("entertheno.:");scanf("%d",&n);for(i=1;i我没有写return12,但是每次执行程序还是返回12。谢谢。 最佳答案 正如swegi所说,它是未定义的行为。正如SteveJessop等人所说,它在C89之前是一个未指定的值,并在C99中指定(观察到的行为不符合C99)在大多数环境中实际发生的是最后一