forked from gravatasufoca/Twin2cc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththreads.c
45 lines (35 loc) · 1.04 KB
/
threads.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <sys/time.h>
#include <time.h>
#include <pthread.h>
#include <sys/socket.h>
#include <unistd.h>
#include <netdb.h>
#include <netinet/in.h>
#include <netinet/ip.h>
#include <netinet/tcp.h>
#include <errno.h>
#include "common.h"
#include "debug.h"
#include "threads.h"
int create_prio_thread(pthread_t *tid, threadfn func, void *arg, int newprio) //0 to 99
{
pthread_attr_t tattr;
int ret;
struct sched_param param;
/* initialized with default attributes */
ret = pthread_attr_init (&tattr);
/* safe to get existing scheduling param */
ret = pthread_attr_getschedparam (&tattr, ¶m);
/* set the priority; others are unchanged */
param.sched_priority = newprio;
/* setting the new scheduling param */
ret = pthread_attr_setschedparam (&tattr, ¶m);
/* with new priority specified */
ret = pthread_create (tid, &tattr, func, arg);
//pthread_create(&th_id,NULL,&ConnectThread, NULL);
return ret;
}