问题列表 - 第47420页

原子内建函数可以跨多个进程使用吗?

我将从.NET重新使用C,因此请原谅我的代码,但是我试图在现有的多进程程序中实现原子内置的增量器。

我写了一个测试程序,但无法正常工作。正确地将其增加到5,但是每个子级将值增加到6,而不是将其总和增加到10。监视器显示5。

我已经尝试过使用全局int进行各种更改,而不是将static int从main传递给子级,但是结果相同。任何帮助表示赞赏,谢谢。

  1 #include <stdio.h>
  2 #include <string.h>
  3 #include <sys/types.h>
  4 #include <stdlib.h>
  5 #include <unistd.h>
  6 #include "list.h"
  7 
  8 #define N 5
  9 static int globalcount = 0;
 10 
 11 void Monitor()
 12 {
 13     sleep(1);
 14     printf("Monitor Value %d\n", globalcount);
 15 }
 16 
 17 void Child()
 18 {   
 19     int value = __sync_add_and_fetch(&globalcount, 1);
 20     printf("Child Value %d\n", value);
 21 }
 22 
 23 int main(int argc, char** argv)
 24 {
 25     int i;
 26 …
Run Code Online (Sandbox Code Playgroud)

c fork atomic built-in-types

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

网站的Apple Touch图标

到目前为止,我一直在脑海中包含Apple Touch图标的行,如下所示:

<link rel="apple-touch-icon" href="/apple-touch-icon.png">

但是,在问答中"苹果触摸图标的正确像素尺寸是多少?" 在公认的答案中说明,根据Apple的指导原则,现在需要三张图片.

那么如何将这些插入代码的head部分呢?

html apple-touch-icon mobile html5

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

如何绑定到 XAML、WPF 中的附加属性

我想将 User.Password 属性绑定到 PasswordBox (TwoWay)。由于PasswordBox.Password 不可绑定,我制作了 AttachedProperties 来解决此问题(一个用于激活绑定,一个用于保存实际密码)。问题是它们不会绑定(GetBindingExpression 返回 null)。

还:

  • AttachedProperties 起作用。如果我在密码框中键入内容,则密码和密码值(附加属性)会正确设置,但 User.Password 仍为空。
  • 绑定 AttachedProperty 也可以工作,但只有相反:如果我将 PasswordValue 绑定到 TextBlock(TextBlock.Text 是目标,helper:PasswordValue 是源),它就可以工作。只是我不能使用它,因为 User 的属性不是依赖对象。
  • User.Password 是可绑定的(User 实现 INotifyPropertyChanged),并且我设法将 User.Username 绑定到 TextBox.Text 并且(用户名和密码是类似的字符串属性)

以下是附加属性:

public static bool GetTurnOnBinding(DependencyObject obj)
        {
            return (bool)obj.GetValue(TurnOnBindingProperty);
        }

        public static void SetTurnOnBinding(DependencyObject obj, bool value)
        {
            obj.SetValue(TurnOnBindingProperty, value);
        }

        // Using a DependencyProperty as the backing store for TurnOnBinding. This enables animation, styling, binding, etc...
        public static readonly DependencyProperty TurnOnBindingProperty =
            DependencyProperty.RegisterAttached(
            "TurnOnBinding",
            typeof(bool),
            typeof(PasswordHelper), …
Run Code Online (Sandbox Code Playgroud)

data-binding wpf binding attached-properties

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

依赖注入 - 我不明白!

好吧,所以我正在玩Ninject,一个"服务层"和一个"存储库层".

我构建了一个简单的控制台应用程序来玩,这就是我想出的:

Imports Ninject

Module Module1

    Sub Main()
        Dim Kernel As IKernel = New StandardKernel(New CustomerModule)
        Dim Service = Kernel.Get(Of CustomerService)()
        Console.WriteLine(Service.GetCustomerByID(1).Name)
        Console.Read()

    End Sub

End Module

#Region "Services"

Public Class CustomerService
    Private _Repository As ICustomerRepository

    <Inject()> _
    Public Sub New(ByVal Repository As ICustomerRepository)
        _Repository = Repository

    End Sub

    Public Function GetCustomerByID(ByVal ID As Integer) As Customer
        Return _Repository.GetByID(ID)
    End Function

End Class

#End Region

#Region "Repositories"

Public Interface IRepository(Of T)
    Function Query(ByVal Predicate As Expressions.Expression(Of Func(Of T, Boolean))) As …
Run Code Online (Sandbox Code Playgroud)

vb.net dependency-injection ninject

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

#pragma omp flush在线程之间建立交换数据

你写了一个非常简单的例子,说明如何使用omp flush来交换数据,以生产者 - >消费者的方式,在线程中我发现了一个有趣的行为.

int a=-1;
int flag=1;
int count=0;
#pragma omp parallel  num_threads(2)
{ 
    int TID;
    TID=omp_get_thread_num();
#pragma omp sections 
    {

#pragma omp section /////////// Producer
        {

            for(int i=0; i<9;i++)
            {
                a=i;
#pragma omp flush(a)
                flag=1;
                printf("Producer a: %d  flag:%d  TID %d \n",a,flag,TID);

                while(flag)
                {

#pragma omp flush(flag)

                }

            }
            flag=2;
#pragma omp flush(flag)

        } // end producer

#pragma omp section  /////////// Consumer
        {
            while(1) {
                count++;

                flag=0;
                while(!flag)
                {
#pragma omp flush(flag)
                }
#pragma omp flush(a)
                printf("Consumer a: …
Run Code Online (Sandbox Code Playgroud)

c openmp

3
推荐指数
1
解决办法
5105
查看次数

使用图层或z-index在画布上绘制形状/文本

我使用for循环绘制了几个文本元素.但我想要在所有其他元素之上绘制第一个元素.除了反转循环之外,还有一种方法可以为文本或形状等绘制元素定义图层编号吗?

html5 canvas

3
推荐指数
1
解决办法
7018
查看次数

wp7上的实体框架

我发现一些博客看起来像是在使用Entity Framework将数据从Windows手机通过WCF保存到远程服务器(至少那就是扫描信息的样子)......但实体框架可以直接在电话?例如,假设我想使用Sqlite,甚至Azure作为我的后端...我可以在没有托管服务器的情况下完成所有工作吗?

c# entity-framework windows-phone-7

9
推荐指数
1
解决办法
745
查看次数

CSS如何打印具有背景颜色的表(不更改打印设置)

目的是用彩色td-s打印表格.我需要一种适合所有类型浏览器的方法.

有什么办法吗?

css html-table

37
推荐指数
3
解决办法
8万
查看次数

如何指定所有表应包含某些字段?

我已经用很多表(大约40个)定义了我的数据库.我现在意识到我想在每个表中添加某些列.为了这个例子,让它成为 created_byupdated_by.

有没有办法在不进行40次迁移的情况下轻松完成这些操作并手动更新每个迁移?

我正在使用rails 2.3.8

ruby-on-rails rails-migrations

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

如何通过UINavigationController设置navigationController?

我正在使用推送通知。单击通知中的操作按钮时,我试图在NavigationController中创建并推送DetailView。但navigationController为零。如何将那个DetailView放在navigationController中?我想在navigationController中然后在DetailView中推送RootViewController。我怎样才能做到这一点?

AppDelegate中

  - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
            RootViewController *controller = [[RootViewController alloc] init];
//getting warnings here.(Unused variable navigationController)  
     UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:controller];
    [controller doStuff];
    [controller release];
 }
Run Code Online (Sandbox Code Playgroud)

RootViewController中

  -(void)doStuff{ 
        [[self stories] removeAllObjects];
    [self startParsing];
    [self.tableView reloadData];
    DetailViewController *detail = [[DetailViewController alloc] init];
    //custom code
   [self.navigationController pushViewController:detail animated:YES];
[detail release];
Run Code Online (Sandbox Code Playgroud)

这是即时消息正在使用的代码。和请注意,我有

 [self.tableView reloadData];
Run Code Online (Sandbox Code Playgroud)

iphone cocoa-touch objective-c uinavigationcontroller apple-push-notifications

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