小编Bil*_*das的帖子

如何在C#中终止一个线程?

我想试试用C#进行线程化,我知道一些关于C语言的线程.

所以我只是想问一下我是否要终止一个线程,我应该这样做,smt.Abort() 否则它会在函数结束后"自杀"?

另外,pthread_exit()在C#中有类似C的东西 吗?

c# multithreading

15
推荐指数
2
解决办法
5万
查看次数

多线程C程序中的线程ID错误?

我是C语言中的多线程新手,我有这个问题.我写了以下代码:

#include <stdio.h>
#include <pthread.h>
#include <unistd.h>

pthread_mutex_t m=PTHREAD_MUTEX_INITIALIZER;
pthread_attr_t attr;

void* test(void *a)
{
    int i=*((int *)a);
    printf("The thread %d has started.\n",i);
    pthread_mutex_lock(&m);
    sleep(1);
    printf("The thread %d has finished.\n",i);
    pthread_mutex_unlock(&m);
    pthread_exit(NULL);

}

int main()
{
    int i=0;
    pthread_attr_setdetachstate(&attr,PTHREAD_CREATE_JOINABLE);
    pthread_t thread[5];

    for (i=0;i<5;i++)
        pthread_create(&thread[i],&attr,test,&i);

    for (i=0;i<5;i++)
        pthread_join(thread[i],NULL);
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

为什么我会得到如下值:

The thread 0 has started.
The thread 0 has started.
The thread 5 has started.
The thread 5 has started.
The thread 0 has started.
The thread 0 has …
Run Code Online (Sandbox Code Playgroud)

c multithreading

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

如何在c#中单击鼠标左键时是否按下了ctrl,alt?

如果CtrlAlt按下鼠标左键,我想查看我的表格 .有没有办法检查它?

c#

0
推荐指数
2
解决办法
3726
查看次数

标签 统计

c# ×2

multithreading ×2

c ×1