小编Adr*_*uer的帖子

如何使用pthreads屏障?

嗨很抱歉发布了一大堆代码,但我是C代码的新手,基本上我正在做大学的任务,我必须实现一个"pthread_barrier",现在我理解了障碍的概念(或者在至少我认为我这样做但是我只是不确定我应该把它放在哪里.作业说明:

"使用pthread_barrier_init和pthread_barrier_wait确保所有生产者/消费者线程同时开始生产/消费."

顺便说一下,这是作业的额外学分

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

#define SIXTY_SECONDS 60000000
#define ONE_SECOND 1000000
#define RANGE 10
#define PERIOD 2

typedef struct {
  int *carpark;
  int capacity;
  int occupied;
  int nextin;
  int nextout;
  int cars_in;
  int cars_out;
  pthread_mutex_t lock;
  pthread_cond_t space;
  pthread_cond_t car;
  pthread_barrier_t bar;
} cp_t;

/* Our producer threads will each execute this function */
static void *
producer(void *cp_in)
{    
  cp_t *cp;
  unsigned int seed;
  /* Convert what was passed in to a pointer …
Run Code Online (Sandbox Code Playgroud)

c linux pthread-barriers

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

何时首次创建共享首选项文件?

我想知道什么时候第一次创建共享首选项文件?

我有以下代码:

<?xml version="1.0" encoding="utf-8"?>  
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">  
    <PreferenceCategory android:title="User settings">  
        <EditTextPreference android:title="User Name"
        android:key="userName" android:summary="Please Enter User Name"></EditTextPreference>  
        <EditTextPreference android:title="Password"
        android:key="password" android:summary="Password Here"
        android:inputType="textPassword"></EditTextPreference>
</PreferenceCategory>  

</PreferenceScreen>  


  public class PrefsActivity extends PreferenceActivity {  
    /** Called when the activity is first created. */  
    @Override  
    public void onCreate(Bundle savedInstanceState) {  
        super.onCreate(savedInstanceState);  
        addPreferencesFromResource(R.xml.prefs);  
    }  
}  
Run Code Online (Sandbox Code Playgroud)

另外,我如何使用带文件名的getSharedpreference()?我不知道是否必须先创建此文件并将其放在app的数据目录中?

我的意思是什么时候首次创建共享首选项文件:安装应用程序时,还是以后某个时间?如果以后,什么时候?

android sharedpreferences

6
推荐指数
1
解决办法
1万
查看次数

在PDO :: bindValue()中使用显式数据类型有什么意义?

使用显式数据类型有PDO::bindValue()什么意义?

例如,在以下任何一种形式中都会有 SQLSTATE[HY000]: General error: 1366 Incorrect integer value: 'a'

$pdos->bindValue(':Value_For_An_Int_Col', 'a');//default arg for the third and opt par is  PDO::PARAM_INT

$pdos->bindValue(':Value_For_An_Int_Col', 'a', PDO::PARAM_INT);
Run Code Online (Sandbox Code Playgroud)

php mysql pdo placeholder bindvalue

6
推荐指数
1
解决办法
404
查看次数

如何在FireFox3中打印Flex组件?

感谢FireFox对ActiveX组件的错误实现(打印时真的应该拍摄它们的图像)Flex组件(在我们的例子图表中)不能在FX中打印.

它们在IE7中打印得很好,甚至是IE6.

我们需要打印这些图表,但它们也有动态内容.当用户打印时,我真的不想再将它们作为图像绘制 - Flex组件应该这样做.

我们已经找到了一个潜在的解决方法,但不幸的是它在FireFox3中不起作用(在FireFox2中它有点可行,但还不够好).

有人知道解决方法吗?

apache-flex firefox actionscript-3

5
推荐指数
1
解决办法
1407
查看次数

如何在drupal中创建pdf文件?

我想在drupal .module文件中创建pdf文件.

我有批量操作的视图,其中我添加了一个操作发送pdf文件并下载pdf文件.我想从数据库中获取一些数据并从中创建一个pdf文件,当我选择一个操作时,它应该创建并在电子邮件中发送pdf文件.

那我怎么能这样做?

php drupal

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

如何以编程方式读取apk文件的内容?

我需要以编程方式阅读apk文件(包括AndroidManifest.xml)的内容。我知道有一些类似的工具apktooldex2jaraapt提取的apk的内容,但是,我需要做同样通过Android应用程序。顺便说一下,我的出发点是一个有效的apk文件路径

java android apk dex android-sdk-tools

5
推荐指数
1
解决办法
3883
查看次数

如何使用 php 在不同的页面中访问我的会话变量?

我在login.php 页面的顶部启动了会话变量。然后设置会话,我使用 include 语句调用第二页。我用 if 语句进行了测试,它似乎通过了。然后我尝试在新显示的页面中回显变量的内容。页面显示意味着它通过了 if 块,但会话变量的内容没有显示。就好像会话变量已经超出了范围。如何在不同的页面中访问我的会话变量。

 <?php
 session_start();
 $username = "";

 if (isset($_POST['submit']))
     {
     $username = $_POST["username"];
     $password = $_POST["password"];
     $_SESSION["username"] = $found_admin["username"];
     if (isset($_SESSION["username"]));
     {
     redirect_to("index.php");
     }
      else
    {
    $_SESSION["message"] = "Username/password not found.";
    }
    }

 ?>


 <?php include("login.html"); ?>
Run Code Online (Sandbox Code Playgroud)

这是我的 php 文件调用的 html 页面:

 <!doctype html>

 <head>

 </head>
 <body>
 <?php

 echo $_SESSION["username"];
 $loggenOnUser=$_SESSION["username"];
 ?>
<div class="gridContainer clearfix">
    <div id="div1" class="fluid">
This page is being called by my login.php file.</div><div id="LoggedInUser" class="fluid ">Hi.  I'm <?php $loggenOnUser?> </div> …
Run Code Online (Sandbox Code Playgroud)

html php session redirect

5
推荐指数
1
解决办法
4万
查看次数

如何使用此备份脚本排除文件夹?

我正在使用这个很棒的脚本来备份我的服务器上的文件夹,但是我想从备份中排除几个文件夹.我该如何排除他们?

谢谢

<?php
/*
 * PHP: Recursively Backup Files & Folders to ZIP-File
 * (c) 2012-2014: Marvin Menzerath - http://menzerath.eu
 * contribution: Drew Toddsby
*/

// Make sure the script can handle large folders/files
ini_set('max_execution_time', 600);
ini_set('memory_limit','1024M');

// Start the backup!
zipData('/var/www/html/uploaded', '/var/www/html/uploaded.zip');
echo 'Finished.';

// Here the magic happens :)
function zipData($source, $destination) {
    if (extension_loaded('zip')) {
        if (file_exists($source)) {
            $zip = new ZipArchive();
            if ($zip->open($destination, ZIPARCHIVE::CREATE)) {
                $source = realpath($source);
                if (is_dir($source)) {
                    $iterator = new RecursiveDirectoryIterator($source);
                    // …
Run Code Online (Sandbox Code Playgroud)

php algorithm backup zip file

5
推荐指数
1
解决办法
997
查看次数

使用PHP从JSON更新MySQL表

大家好,感谢您的耐心配合,

我正在尝试编写cron作业以更新MySQL数据库中的货币汇率。我正在接收的JSON数据如下所示;

{
  "disclaimer": "Exchange rates are provided for informational purposes only, and do not constitute financial advice of any kind. Although every attempt is made to ensure quality, NO guarantees are given whatsoever of accuracy, validity, availability, or fitness for any purpose - please use at your own risk. All usage is subject to your acceptance of the Terms and Conditions of Service, available at: ",
  "license": "Data sourced from various providers with public-facing APIs; copyright may apply; resale …
Run Code Online (Sandbox Code Playgroud)

php mysql sql arrays json

5
推荐指数
1
解决办法
4285
查看次数

如何从 onActivityResult 获取任何文件路径、名称、扩展名?

我的代码是:

1.

File file = new File(Environment.getExternalStorageDirectory(),"myFolder");

            Log.d("path", file.toString());

        Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
        intent.setDataAndType(Uri.fromFile(file), "*/*");
        startActivityForResult(intent,0);
Run Code Online (Sandbox Code Playgroud)

2.

 @Override
    protected void onActivityResult(int requestCode, 
    int resultCode, Intent FileReturnedIntent) {
            // TODO Auto-generated method stub
            super.onActivityResult(requestCode, resultCode, FileReturnedIntent);
Run Code Online (Sandbox Code Playgroud)

如何获取文件路径、名称、扩展名?(假设文件为 doc、pdf、csv 格式)

android onactivityresult

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