小编use*_*116的帖子

如何创建随机值的枚举?

我怎样才能获得IEnumerable随机值?我对班级Random没有实现感到失望IEnumerable<int>.

.net c# random ienumerable

0
推荐指数
1
解决办法
460
查看次数

使用printf("something")或system("echo something")会花费更多的处理能力吗?

这个问题属于ANSI C.我认为它应该是一个简单的答案......所以这些方法中哪一个最快?它与我目前的项目没有任何关系,但有一天我想到了,我没有立即在网上看到答案......

c performance

0
推荐指数
1
解决办法
354
查看次数

为什么pthread_cond_signal不起作用?

我目前正在学习所有POSIX线程(pthread).

我现在已经创建了一个简单的程序,它将共享值增加7直到10000以上然后它应该向下一个线程发出一个条件,它将它减少3直到1000以下.最后它应该将结果除以2并且main应该输出结果.

我的代码:

pthread_t threads[3];
pthread_cond_t cond_a, cond_b;
pthread_mutex_t mutex;

int counter;

void * worker_one();
void * worker_two();
void * worker_three();

int main(int argv, const char ** argc) {
    counter = 0;

    pthread_cond_init(&cond_a, NULL);
    pthread_cond_init(&cond_b, NULL);
    pthread_mutex_init(&mutex, NULL);

    pthread_create(&threads[0], NULL, worker_one, NULL);
    pthread_create(&threads[1], NULL, worker_two, NULL);
    pthread_create(&threads[2], NULL, worker_three, NULL);

    pthread_join(threads[0], NULL);
    pthread_join(threads[1], NULL);
    pthread_join(threads[2], NULL);

    printf("Value started at %d and ends with %d.\n", 0, counter);

    return 0;
}

void * worker_one() {
    printf("Worker one started.\n");

    pthread_mutex_lock(&mutex);

    printf("Worker one …
Run Code Online (Sandbox Code Playgroud)

c multithreading pthreads

0
推荐指数
1
解决办法
2580
查看次数

LINQ表达式而不是嵌套的foreach循环

所以我有List,其中每个元素都是一个字符串数组

List<string[]> TokenList = new List<string[]>();
Run Code Online (Sandbox Code Playgroud)

我想在列表中的每个数组中显示数组中的每个元素.为此,我使用嵌套的foreach循环.

foreach (var temp in pro.TokenList)
        {
            foreach (var s in temp)
            {
                Console.WriteLine(s);
            }
        }
Run Code Online (Sandbox Code Playgroud)

现在我想在我的程序中使用LINQ,我想知道将使用什么样的LINQ查询来实现相同的期望结果.

.net c# linq

0
推荐指数
1
解决办法
2116
查看次数

有条件不工作,总是返回第一个案例

结果打印出"c"3次,任何人都知道它为什么总是满足第一个条件?

#include <iostream>

using namespace std;


char x(char y)
{
    if (y == 'a' || 'b')
    {
        return 'c';
    }
    else if (y == 'c' || 'd')
    {
        return 'e';
    }
    else
    {
        return 'g';
    }
}


int main()
{
    cout << x('a') << endl;
    cout << x('c') << endl;
    cout << x('p') << endl;
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

c++ operators

-1
推荐指数
2
解决办法
78
查看次数

这个代码在任何C标准下都有效吗?

此代码是否遵循C标准(例如C89,C99,C10x)?

void 
main(int a,int b, int c, int d,char *msg){
    if(d==1){
        printf("%s\n",msg);
    }else{
        main(1,2,3,1,&"Hello Stackoverflow");
    }
}
Run Code Online (Sandbox Code Playgroud)

如果没有,为什么?

c program-entry-point

-2
推荐指数
1
解决办法
208
查看次数