我已经阅读了很多关于我的问题的google结果,任何方法都无法帮助我。 #define _GNU_SOURCE
#include <pthread.h>
#include <sched.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <unistd.h>
#include <semaphore.h>
sem_t sem;
void *start1(void *p)
{
pthread_mutex_lock(p);
sem_post(&sem);
sem_post(&sem);
usleep(100000);
pthread_mutex_unlock(p);
return 0;
}
void *start2(void *p)
{
sem_wait(&sem);
time_t t0 = time(0);
while (pthread_mutex_trylock(p)) {
if (time(0)>t0+5) return 0;
}
pthread_mutex_unlock(p);
return 0;
}
void *start3(void *p)
{
sem_wait(&sem);
struct timespec ts;
clock_gettime(CLOCK_REALTIME, &ts);
ts.tv_sec += 5;
int r;
if (r=pthread_mutex_timedlock(p, &ts)) {
printf("failed: %d %s\n", r, strerror(r));
} else {
pthread_mutex_unlock(p);
}
return 0;
}
int main(int argc, char **argv)
{
int policy = argc>1 ? SCHED_IDLE : SCHED_FIFO;
int a = sched_get_priority_min(policy);
pthread_attr_t attr;
pthread_t t1,t2,t3;
struct sched_param param = {0};
cpu_set_t set = {0};
CPU_ZERO(&set);
CPU_SET(0, &set);
pthread_setaffinity_np(pthread_self(), sizeof set, &set);
pthread_attr_init(&attr);
pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED);
pthread_attr_setschedpolicy(&attr, policy);
pthread_mutexattr_t ma;
pthread_mutexattr_init(&ma);
pthread_mutexattr_setprotocol(&ma, PTHREAD_PRIO_INHERIT);
pthread_mutexattr_settype(&ma, PTHREAD_MUTEX_ERRORCHECK);
pthread_mutex_t mtx;
pthread_mutex_init(&mtx, &ma);
sem_init(&sem, 0, 0);
param.sched_priority = a+1;
pthread_attr_setschedparam(&attr, ¶m);
if (pthread_create(&t2, policy==SCHED_IDLE ? 0 : &attr, start2, &mtx)) return 1;
param.sched_priority = a+2;
pthread_attr_setschedparam(&attr, ¶m);
if (pthread_create(&t3, policy==SCHED_IDLE ? 0 : &attr, start3, &mtx)) return 1;
param.sched_priority = a;
pthread_attr_setschedparam(&attr, ¶m);
if (pthread_create(&t1, &attr, start1, &mtx)) return 1;
pthread_join(t1, 0);
pthread_join(t2, 0);
pthread_join(t3, 0);
return 0;
}
返回了一个空数组,我尝试修复了两天。我曾经尝试过很多方法,无论是stackoverlow还是其他网站,都无法使用这种方法。 print_r($_POST)
是空数组。
我的代码
$_POST
我的文本区域
<?php
require_once 'config.php';
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
function updateRec($tbl, $index) {
if($GLOBALS['connection'] !== null) {
$connection = $GLOBALS['connection'];
if($tbl == 'users') {
//if(isset($_POST['id']) && isset($_POST['username']) && isset($_POST['password']) && isset($_POST['rank'])) {
$id = $_POST['id'];
$login = test_input($_POST['username']);
$pass = password_hash(test_input($_POST['password']), PASSWORD_DEFAULT);
$rank = test_input($_POST['rank']);
$q = "UPDATE $tbl SET id='$id', username='$login', password='$pass', rank='$rank' WHERE id='$index'";
echo "<script type='text/javascript'>alert(".$login.");</script>";
//}
}
//mysqli_query($connection, $q);
header('location: '.$tbl.'.php?page=1');
}
}
function createForm($a) {
if ($a === 'edit') {
echo "<center><div id='editForm'>";
$q = "DESCRIBE ".$_GET['tbl']."";
$qr = mysqli_query($GLOBALS['connection'], $q);
while ($rw = mysqli_fetch_array($qr)) {
echo "<tr>";
echo "<td> " . $rw['Field'] . "</td><br/>";
echo "<td><textarea rows='4' cols='50' name='".$rw['Field']."' required></textarea></td>";
echo "<br/>";
echo "</tr>";
}
echo '<form action="forms.php?action=saveE&tbl='.$_GET['tbl'].'&row='.$_GET['row'].'" method="post" accept-charset="utf-8" style="transform: translate(5vw, -20vh); height: 0vh;">';
echo '<button id="fButton" name="submit" style="">Zapisz</button></form>'. '<a href="'.$_GET['tbl'].'.php?page=1"><button id="fButton" style="transform: translate(5vw, 8vh); margin-left: 6%;">Anuluj</button></a>';
print_r($_POST);
echo "</div></center>";
};
if ($a === 'saveE') {
updateRec($_GET['tbl'], $_GET['row']);
};
}
?>
<!DOCTYPE html>
<html lang="pl">
<head>
<title>Control Panel</title>
<link rel="stylesheet" type="text/css" href="global.css">
<meta charset="utf-8" name="viewport" content="width=device.width, initial-scale=1">
</head>
<body>
<header>
<p>Admin Control Panel</p>
</header>
</body>
</html>
我也尝试使用id代替名称,但这对我没有帮助。