我是pthreads的新手,我正在努力理解它.我看到了一些如下例子.
我可以看到它main()被API阻止了pthread_exit(),我已经看到了主要功能被API阻止的示例pthread_join().我无法理解何时使用什么?
我指的是以下网站 - https://computing.llnl.gov/tutorials/pthreads/.我无法获得何时使用pthread_join()以及何时使用的概念pthread_exit().
有人可以解释一下吗?此外,pthreads的良好教程链接将不胜感激.
#include <pthread.h>
#include <stdio.h>
#define NUM_THREADS 5
void *PrintHello(void *threadid)
{
long tid;
tid = (long)threadid;
printf("Hello World! It's me, thread #%ld!\n", tid);
pthread_exit(NULL);
}
int main (int argc, char *argv[])
{
pthread_t threads[NUM_THREADS];
int rc;
long t;
for(t=0; t<NUM_THREADS; t++){
printf("In main: creating thread %ld\n", t);
rc = pthread_create(&threads[t], NULL, PrintHello, (void *)t);
if (rc){
printf("ERROR; return code from pthread_create() is %d\n", …Run Code Online (Sandbox Code Playgroud) 我正在尝试设置smtp电子邮件通知.我可以看到gmail部分工作正常.我想为我的办公室365配置它.
Smtp服务器= smtp.office365.com
我们没有配置SSL.相反,我们使用TLS.如何在Jenkins中设置TLS?只有一个检查按钮,建议使用SSL或不使用SSL.如果我禁用它会使用什么?
我收到以下错误 -
Failed to send out e-mail
javax.mail.MessagingException: Could not connect to SMTP host: smtp.office365.com, port: 587;
nested exception is:
javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1934)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:638)
at javax.mail.Service.connect(Service.java:317)
at javax.mail.Service.connect(Service.java:176)
at javax.mail.Service.connect(Service.java:125)
at javax.mail.Transport.send0(Transport.java:194)
at javax.mail.Transport.send(Transport.java:124)
at hudson.tasks.Mailer$DescriptorImpl.doSendTestMail(Mailer.java:499)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:616)
at org.kohsuke.stapler.Function$InstanceFunction.invoke(Function.java:298)
at org.kohsuke.stapler.Function.bindAndInvoke(Function.java:161)
at org.kohsuke.stapler.Function.bindAndInvokeAndServeResponse(Function.java:96)
at org.kohsuke.stapler.MetaClass$1.doDispatch(MetaClass.java:120)
at org.kohsuke.stapler.NameBasedDispatcher.dispatch(NameBasedDispatcher.java:53)
at org.kohsuke.stapler.Stapler.tryInvoke(Stapler.java:728)
at org.kohsuke.stapler.Stapler.invoke(Stapler.java:858)
at org.kohsuke.stapler.MetaClass$6.doDispatch(MetaClass.java:248)
at org.kohsuke.stapler.NameBasedDispatcher.dispatch(NameBasedDispatcher.java:53)
at org.kohsuke.stapler.Stapler.tryInvoke(Stapler.java:728)
at org.kohsuke.stapler.Stapler.invoke(Stapler.java:858)
at org.kohsuke.stapler.Stapler.invoke(Stapler.java:631)
at …Run Code Online (Sandbox Code Playgroud) 我无法理解Q_PROPERTY的用法.Q_PROPERTY如何帮助使程序防御?它是干什么用的?我见过论坛,但真的无法进行论坛.我已经理解了这个例子,但不是它的用法.
这是一个例子,我从中获得了什么.我知道阅读会给予阅读权限.
write属性将赋予仅写入权限.但它有什么需要呢?有人可以举例说明吗?
class MyClass : public QObject
{
Q_OBJECT
Q_PROPERTY(Priority priority READ priority WRITE setPriority NOTIFY priorityChanged)
Q_ENUMS(Priority)
public:
MyClass(QObject *parent = 0);
~MyClass();
enum Priority { High, Low, VeryHigh, VeryLow };
void setPriority(Priority priority)
{
m_priority = priority;
emit priorityChanged(priority);
}
Priority priority() const
{ return m_priority; }
signals:
void priorityChanged(Priority);
private:
Priority m_priority;
};
Run Code Online (Sandbox Code Playgroud) 在构建dbus示例时,我发现我们需要在gcc中添加pkg-config.例如:
gcc `pkg-config --cflags --libs dbus-1` <file_name> -o <file_name.out>
Run Code Online (Sandbox Code Playgroud)
有什么意义pkg-config --cflags --libs dbus-1?这是什么pkg-config?什么是额外的cflags?什么在--libs这里?
我有以下数据结构.
QList<QVariant> fieldsList
Run Code Online (Sandbox Code Playgroud)
我该如何排序这个清单?此列表包含字符串.我想fieldList按字母顺序排序?
我正在尝试设置构建命令,我收到这些错误.我尝试过设置安全配置.
访问控制:
授权:基于矩阵.
用户组:joshis1 - 全部检查.
运行构建后.我得到以下错误.在构建脚本中,我只是想复制一个文件.
Started by user shreyas joshi
Building in workspace /var/lib/jenkins/workspace/Tungsten-Build
[Tungsten-Build] $ /bin/sh /tmp/hudson1841543545003586844.sh
November26
November26
sudo: sorry, you must have a tty to run sudo
sudo: sorry, you must have a tty to run sudo
sudo: sorry, you must have a tty to run sudo
sudo: sorry, you must have a tty to run sudo
sudo: sorry, you must have a tty to run sudo
sudo: sorry, you must have …Run Code Online (Sandbox Code Playgroud) 在套接字编程中,我看到服务器绑定到一个地址 - 包括IP和端口号.然后步骤是监听,并接受(阻止呼叫).我想知道为什么客户端不需要绑定其IP地址和端口号.实际上,它与服务器套接字地址绑定.然后,客户端调用connect()调用以建立连接.之后,客户端和服务器都可以互相通话.服务器如何与客户端通话?客户端未绑定其IP地址和端口号.服务器如何才能到达客户端?
让我举例说明一下,
int a = 100;
int b = a;
int main(int argc, char **argv, char ** env)
{
printf("The value of b=%d\r\n",b);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
现在,我按预期得到了编译错误.
[joshis1@localhost global_var]$ gcc global_var.c -o global_var.out
global_var.c:4:1: error: initializer element is not constant
int b = a;
^
Run Code Online (Sandbox Code Playgroud)
我想在这里学到的是为什么我会得到错误?为什么编译器限制此操作.我知道初始化的全局变量存储在数据段中.编译器可以首先解析a的值,然后可以为b分配相同的值.为什么它缺少这个功能?编译器复杂吗?这个功能背后是否有任何理由或只是C的陷阱?
我正在寻找识别磁盘是SSD还是HDD的方法?我发现有一种方法可以检测到它.这是通过读取cat/sys/block/sda/queue/rotation的值?如果它是1那么它是HDD,否则它是SSD.我想知道这个文件是什么/ sys/block/sda/queue/rotate?为什么它被内核使用?这个由内核维护的k对象是什么?
我试图理解C中范围的确切含义.我能理解的是范围仅限于编译时间.例如,如果您从其他某个函数访问局部变量.这将导致编译时错误.另一方面,以下程序工作正常.这意味着C具有平坦的内存模型,并且可以在运行时访问任何内容.C书将范围与生命周期和可变可见性联系起来,我发现它很混乱.我认为所有这些术语仅适用于编译时.有人可以点亮吗?
#include "stdio.h"
int *ptr;
int func(void)
{
/** abc is a local variable **/
int abc = 132;
ptr = &abc;
return 0;
}
int func1(void)
{
/** although scope of abc is over still I can change the value in the address of abc **/
*ptr = 200;
printf("the value of abc=%d\r\n",*ptr);
}
int main(void)
{
func();
func1();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
结果:值abc= 200
用简单的话来说,范围是什么意思?它是在运行时还是编译时出现的?我们可以看到,我们可以在运行时访问任何内容.但是,如果我们不遵守规则,那么我们将得到编译错误.例如,另一个函数中的局部变量引用.编译器将抛出一个错误,说"变量未定义......".
我可以对变量说以下内容吗?
1) Scope attribute comes under compile time.
2) Lifetime attribute comes …Run Code Online (Sandbox Code Playgroud) c ×4
linux ×4
jenkins ×2
qt ×2
c++ ×1
gcc ×1
linux-kernel ×1
pkg-config ×1
pthreads ×1
qobject ×1
qproperty ×1
qt-signals ×1
qvariant ×1
sockets ×1
sorting ×1