pthread

How to use pthread on Qt Creator

匿名 (未验证) 提交于 2019-12-03 01:31:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I want to execute a following code. #include #include void output () { std :: cout << "Hello World" << std :: endl ; } int main () { std :: thread t ( output ); t . join (); return 0 ; } I can't execute it. Qt Creator outputs terminate called after throwing an instance of 'std::system_error' what(): Operation not permitted However I can execute on the terminal using the option of -pthread. Could you tell me how to use the option of -pthread in Qt Creator? My developing environment is Ubuntu(12.04), g++4.6.3, Qt Creator(2.4.1).

Difference between -pthread and -lpthread while compiling

匿名 (未验证) 提交于 2019-12-03 01:20:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: What is the difference between gcc -pthread and gcc -lpthread which is used while compiling multithreaded programs? 回答1: -pthread tells the compiler to link in the pthread library as well as configure the compilation for threads. For example, the following shows the macros that get defined when the -pthread option gets used on the GCC package installed on my Ubuntu machine: $ gcc - pthread - E - dM test . c > dm . pthread . txt $ gcc - E - dM test . c > dm . nopthread . txt $ diff dm . pthread . txt dm . nopthread . txt 152d151

LLVM insert pthread function calls into IR

匿名 (未验证) 提交于 2019-12-03 01:12:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm writing a LLVM pass (it's a LoopPass ) that needs to insert pthread functions calls like pthread_create() and pthread_join() into the IR. I know how to create and insert a function call into IR, but I am having trouble to get the pthread representation of Function* in LLVM. Here's what I have: Function *pthread_create_func = currentModule->getFunction("pthread_create"); but it returns NULL. As a comparison Function *printf_func = currentModule->getFunction("printf"); will return the correct Function* that allows me to insert a new

why pthread causes a memory leak

匿名 (未验证) 提交于 2019-12-03 01:10:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Whenever I create a pthread, valgrind outputs a memory leak, For example the below code: #include #include #include void *timer1_function (void *eit){ (void) eit; printf("hello world\n"); pthread_exit(NULL); } int main(void){ pthread_t timer1; pthread_create( &timer1, NULL, timer1_function, NULL); ///////line13 int i=0; for(i=0;i valgrind outputs ==1395== HEAP SUMMARY: ==1395== in use at exit: 136 bytes in 1 blocks ==1395== total heap usage: 6 allocs, 5 frees, 1,134 bytes allocated ==1395== ==1395== 136 bytes in 1 blocks are possibly lost in

Multiple threads in C program

匿名 (未验证) 提交于 2019-12-03 01:08:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm writing a Unix application in C which uses multiple threads of control. I'm having a problem with the main function terminating before the thread it has spawned have a change to finish their work. How do I prevent this from happening. I suspect I need to use the pthread_join primitive, but I'm not sure how. Thanks! 回答1: Yes, you could use pthread_join() (see other anwers for how to do that). But let me explain the pthread model and show you another option. In Unix, a process exits when the primary thread returns from main, when any

Exception Type: EXC_CRASH (SIGABRT)

匿名 (未验证) 提交于 2019-12-03 01:05:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Incident Identifier: B959CD08-FA2C-4A34-8D0C-343927FF6B86 CrashReporter Key: 78e6625f679cb4cfb76f553075c64a197002c1bf Hardware Model: iPad3,1 Process: ktv [50343] Path: /var/mobile/Applications/B8971D06-6001-49F7-81E1-8B88CDA5EB03/ktv.app/ktv Identifier: ktv Version: ??? (???) Code Type: ARM (Native) Parent Process: launchd [1] Date/Time: 2013-01-09 18:59:32.193 +0800 OS Version: iPhone OS 5.1.1 (9B206) Report Version: 104 Exception Type: EXC_CRASH (SIGABRT) Exception Codes: 0x00000000, 0x00000000 Crashed Thread: 0 Thread 0 name: Dispatch

undefined reference to `boost::log_mt_posix::basic_attribute_set&lt;char&gt;::~basic_attribute_set()&#039;

匿名 (未验证) 提交于 2019-12-03 00:47:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Newbie question... I'm trying out Boost for the first time because I want to test drive the Boost Log library. I built this test program... #include <boost/log/trivial.hpp> #include <iostream> int fibonacci(int num) { int i; int a = 1; int b = 1; for (i = 2; i <= num; ++i) { BOOST_LOG_TRIVIAL(info) << "Iteration " << i << " (a = " << a << ", b = " << b << ")..."; b = a + b; a = b - a; } return a; } int main() { std::cout << "8th fibonacci number: " << fibonacci(8) << std::endl; return 0; } Compile data: **** Build of configuration Debug for

Swift / SKStoreProductViewController pushViewController results in (lldb)

匿名 (未验证) 提交于 2019-12-03 00:46:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: To push the user to the iTunes store for desired items I'm using the following function: func openStoreProductWithiTunesItemIdentifier(identifier: String) { let storeViewController = SKStoreProductViewController() storeViewController.delegate = self let parameters = [ SKStoreProductParameterITunesItemIdentifier : identifier, SKStoreProductParameterAffiliateToken : ITUNES_AFFILIATE_ID] storeViewController.loadProductWithParameters(parameters) { [weak self] (loaded, error) -> Void in if loaded { self!.navigationController?

线程中互斥锁mutex来实现同步

匿名 (未验证) 提交于 2019-12-03 00:40:02
pthread_mutex_init()函数用于创建一个互斥量,第一个参数指向互斥量的数据结构pthread_mutex_t的指针,第二个参数是定义互斥量属性的pthread_mutexattr_t结构的指针,他的默认类型是fast。类似于信号量的使用方法, pthread_mutex_lock()是对互斥量进行锁定操作, pthread_mutex_unlock()是对互斥量进行解锁操作, pthread_mutex_destroy()的作用是清除互斥量。 演示互斥量的操作方法 #include <stdio.h> #include <unistd.h> #include <pthread.h> #include <string.h> #include <stdlib.h> #include <semaphore.h> void *thread_function(void *arg); pthread_mutex_t work_mutex; //定义互斥量 #define WORK_SIZE 1024 char work_area[WORK_SIZE]; int time_to_exit=1; int main () { int res; pthread_t a_thread; //保存创建线程的返回值 void *thread_result; //结束线程的返回值 res

连接池模板

匿名 (未验证) 提交于 2019-12-03 00:34:01
/*************************************************************** function: connect pool template for mysql, redis, memcached ... author: liuyi date: 2016.04.13 version: 1.0 ***************************************************************/ #ifndef CONNECT_POOL_H #define COMMECT_POOL_H #include <stdlib.h> #include <iostream> #include <vector> #include <pthread.h> using namespace std; template<class T> class connect_pool { public: static connect_pool<T> * get_instance() { static connect_pool<T> s_instance; return &s_instance; } bool init(vector<T*> connect_ptrs) { if(connect_ptrs.empty()) return