我正在为一个调度队列制作一个ac文件,该队列获取一个任务并将其放入一个链接列表的队列中.为了做到这一点,我需要使用创建线程
pthread_t cThread;
if(pthread_create(&cThread, NULL, work, param)){
perror("ERROR creating thread.");
}
Run Code Online (Sandbox Code Playgroud)
但是我需要创建另一个作为'work'和'param'变量的函数作为create function的参数.我的朋友告诉我,我只需要在无限循环的工作函数中放入任何代码,这样线程就不会死.任何人都可以解释每个参数进入pthread_create函数 - 特别是对于work和param?我搜索谷歌这个,但大多数教程都很难理解这个概念......
我创建了一个自定义按钮并将其应用到UIbarbuttonitem.没有错误,但导航栏上没有显示任何内容:(这是我的代码 -
//create a custom button
UIImage *image = [UIImage imageNamed:@"TESTButton.png"];
UIButton *myCustomButton = [UIButton buttonWithType:UIButtonTypeCustom];
myCustomButton.bounds = CGRectMake( 0, 0, image.size.width, image.size.height );
[myCustomButton setImage:image forState:UIControlStateNormal];
[myCustomButton addTarget:nil action:@selector(goBack:) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *button = [[UIBarButtonItem alloc] initWithCustomView:myCustomButton];
self.navigationItem.leftBarButtonItem = button;
self.navigationController.navigationBar.barStyle = UIBarStyleDefault;
[button release];
[myCustomButton release];
[image release];
[navID release];
Run Code Online (Sandbox Code Playgroud)
谁可以修复我的代码?:)
我dispatchQueue.c:215: warning: control reaches end of non-void function从下面的代码中得到警告..
任何人都可以解释原因吗?
void *dispatcher_threadloop(void *arg){
//thread loop of the dispatch thread- pass the tast to one of worker thread
dispatch_queue_thread_t *dThread = arg;
dispatch_queue_t *dQueue;
dQueue = dThread->queue;
if (dQueue->HEAD!=NULL){
for(;;){
printf("test");
sem_wait(&(dQueue->queue_task_semaphore));
dThread->current_task = dQueue->HEAD;
dQueue->HEAD = dQueue->HEAD->next;
dQueue->HEAD->prev = NULL;
sem_post(&(dQueue->queue_task_semaphore));
break;
//TODO
}
}
Run Code Online (Sandbox Code Playgroud)
}
我正在尝试在UILabel每个单元格中添加一个额外的(UITableView)我在
(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath方法中成功使用了这个代码
这是我的代码
//add another text
UILabel *test = [[UILabel alloc] initWithFrame:CGRectMake(250,80,50,20.0)];
test.text = [NSString stringWithFormat: @"test"];
test.backgroundColor = [UIColor clearColor];
test.font=[UIFont fontWithName:@"AppleGothic" size:20];
[cell addSubview:test];
Run Code Online (Sandbox Code Playgroud)
但是我想如果我这样做,我不能为每个单元格添加不同的文本,而是在所有单元格中以相同的文本结束.谁能告诉我怎么做?
哦,另一个问题是,如果我这样做,除了第一个以外,每个单元格都会显示"test".
int main(int argc, char** argv) {
int i = 0;
while (i < 2) {
fork();
system("ps -o pid,ppid,comm,stat");
i++;
}
return (EXIT_SUCCESS);
}
Run Code Online (Sandbox Code Playgroud)
谁能告诉我ps命令执行了多少次?
任何人都可以告诉我为什么我在这里有分段错误?
void *dispatcher_threadloop(void * queue){
//thread loop of the dispatch thread- pass the tast to one of worker thread
dispatch_queue_t *dQueue;
printf("message-boss1");
dQueue = (dispatch_queue_t *)queue;
if (dQueue->HEAD!=NULL){
for(;;){
sem_wait(dQueue->queue_thread_semaphore);
//TODO
}
}
printf("message-boss2");
}
Run Code Online (Sandbox Code Playgroud) 我现在正在实现gtest,它给了我一个错误:主要在此定义.
这是utest.cpp
// Bring in my package's API, which is what I'm testing
#include "../src/test.cpp"
// Bring in gtest
#include <gtest/gtest.h>
// Declare a test
TEST(TestSuite, testCase1)
{
EXPECT_EQ(5,getX(5));
}
// Run all the tests that were declared with TEST()
int main(int argc, char **argv){
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
Run Code Online (Sandbox Code Playgroud)
这是我正在测试test.cpp的代码
#include "ros/ros.h"
#include "std_msgs/String.h"
#include <Project2Sample/R_ID.h>
#include <geometry_msgs/Twist.h>
#include <nav_msgs/Odometry.h>
#include <sensor_msgs/LaserScan.h>
#include <sstream>
#include "math.h"
int getX(int x)
{
return x;
}
int main(int argc, char **argv)
{ …Run Code Online (Sandbox Code Playgroud) c++ program-entry-point compiler-errors googletest redefinition
c ×4
function ×2
ios ×2
objective-c ×2
c++ ×1
createthread ×1
fork ×1
googletest ×1
if-statement ×1
linux ×1
pthreads ×1
redefinition ×1
uilabel ×1
uitableview ×1
void ×1
warnings ×1