草庐IT

thread_posixs

全部标签

c - 使用 POSIX API 读取文件

考虑以下将文件内容读入缓冲区的代码#include#include#include#include#include#defineBLOCK_SIZE4096intmain(){intfd=-1;ssize_tbytes_read=-1;inti=0;charbuff[50];//Arbitarysizeforthebuffer??Howtooptimise.//Dynamicallocationisachoicebutwhatisthe//rightwaytorelatethefilesizetobufffersize.fd=open("./file-to-buff.txt",O_RD

c - ftruncate 不适用于 Mac OS X 中的 POSIX 共享内存

我在MacOSX上写了一段代码来使用POSIX共享内存,如下所示:#include#include#include#include#includeintmain(){intfileHandle=shm_open("TW_ShMem1",O_CREAT|O_RDWR,0666);if(fileHandle==-1){//error.}else{//Here,itisfailingonMacOSXif(-1==ftruncate(fileHandle,8192)){shm_unlink("TW_ShMem1");fileHandle=-1;}else{return0;}}return1;}

c - ftruncate 不适用于 Mac OS X 中的 POSIX 共享内存

我在MacOSX上写了一段代码来使用POSIX共享内存,如下所示:#include#include#include#include#includeintmain(){intfileHandle=shm_open("TW_ShMem1",O_CREAT|O_RDWR,0666);if(fileHandle==-1){//error.}else{//Here,itisfailingonMacOSXif(-1==ftruncate(fileHandle,8192)){shm_unlink("TW_ShMem1");fileHandle=-1;}else{return0;}}return1;}

linux - POSIX:FreeBSD 与 Linux 中的管道系统调用

在Linux(2.6.35-22-generic)中,manpipe指出pipe()createsapipe,aunidirectionaldatachannelthatcanbeusedforinterprocesscommunication."在FreeBSD(6.3-RELEASE-p5)中,manpipe指出Thepipe()systemcallcreatesapipe,whichisanobjectallowingbidirectionaldataflow,andallocatesapairoffiledescriptors."一个是单向的,一个是双向的。我希望这不是一个愚蠢

linux - POSIX:FreeBSD 与 Linux 中的管道系统调用

在Linux(2.6.35-22-generic)中,manpipe指出pipe()createsapipe,aunidirectionaldatachannelthatcanbeusedforinterprocesscommunication."在FreeBSD(6.3-RELEASE-p5)中,manpipe指出Thepipe()systemcallcreatesapipe,whichisanobjectallowingbidirectionaldataflow,andallocatesapairoffiledescriptors."一个是单向的,一个是双向的。我希望这不是一个愚蠢

c++ - 大多数时候从 POSIX 线程在 C++ 中打开/proc/net/tcp 失败

当我尝试从C++中的子POSIX线程打开/proc/net/tcp时,它失败并显示“没有这样的文件或目录”错误。如果我尝试从父线程打开它,它每次都会成功,而在父线程中打开/关闭它的过程也会使它在子线程中成功大约三分之一的时间。我可以100%地在子线程中打开/proc/uptime而不会出现问题。下面是一些可以用“g++-Walltest.cc-otest-pthread”编译的示例代码:#include#include#include#include#includeusingnamespacestd;void*open_test(void*){ifstreamin;in.open("/

c++ - 大多数时候从 POSIX 线程在 C++ 中打开/proc/net/tcp 失败

当我尝试从C++中的子POSIX线程打开/proc/net/tcp时,它失败并显示“没有这样的文件或目录”错误。如果我尝试从父线程打开它,它每次都会成功,而在父线程中打开/关闭它的过程也会使它在子线程中成功大约三分之一的时间。我可以100%地在子线程中打开/proc/uptime而不会出现问题。下面是一些可以用“g++-Walltest.cc-otest-pthread”编译的示例代码:#include#include#include#include#includeusingnamespacestd;void*open_test(void*){ifstreamin;in.open("/

c++ - std::thread 创建抛出异常

代码:#include#includevoidhello(){std::cout构建:g++-Wall-fexceptions-std=c++0x-pthread-g-c/home/alex/tmp/thread_test/main.cpp-oobj/Debug/main.og++-obin/Debug/thread_testobj/Debug/main.oOutputsizeis106.62KBProcessterminatedwithstatus0(0minutes,0seconds)0errors,0warnings结果:creatingthreadOperationnotper

c++ - std::thread 创建抛出异常

代码:#include#includevoidhello(){std::cout构建:g++-Wall-fexceptions-std=c++0x-pthread-g-c/home/alex/tmp/thread_test/main.cpp-oobj/Debug/main.og++-obin/Debug/thread_testobj/Debug/main.oOutputsizeis106.62KBProcessterminatedwithstatus0(0minutes,0seconds)0errors,0warnings结果:creatingthreadOperationnotper

c++ - std::thread::id 默认构造函数不应该创建一个 "NULL"id 吗?

以下代码在我的gcc版本4.8.0中失败:#include#includeintmain(){std::thread::idnobody;assert(nobody!=std::this_thread::get_id());};这种行为是否正确? 最佳答案 更新:JonathanWakely亲切地查看了这个问题hesays(belowincomments)-pthread必须传递给编译器和链接器。如果我这样做,代码也不会因gcc4.7.2而失败。所以答案显然与引用的电子邮件无关。谢谢乔纳森!这里有一些直接来自gcc开发人员的引述Jo